This is an automated email from the ASF dual-hosted git repository.

kusal pushed a commit to branch WW-5343-sec-extend
in repository https://gitbox.apache.org/repos/asf/struts.git

commit a402e5c80a4fb5d3e98b1ab857549981269468e1
Author: Kusal Kithul-Godage <g...@kusal.io>
AuthorDate: Fri Nov 17 15:28:14 2023 +1100

    WW-5343 Revert and fix serializability
---
 .../com/opensymphony/xwork2/ognl/OgnlValueStack.java   | 18 ++++++++++++++++++
 .../xwork2/util/location/LocationImpl.java             |  9 +++++++++
 2 files changed, 27 insertions(+)

diff --git 
a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java 
b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
index 57a511198..ddcd4429a 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
@@ -21,6 +21,7 @@ package com.opensymphony.xwork2.ognl;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.TextProvider;
 import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
+import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor;
 import com.opensymphony.xwork2.util.ClearableValueStack;
@@ -33,6 +34,7 @@ import ognl.NoSuchPropertyException;
 import ognl.Ognl;
 import ognl.OgnlContext;
 import ognl.OgnlException;
+import ognl.PropertyAccessor;
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -515,6 +517,22 @@ public class OgnlValueStack implements Serializable, 
ValueStack, ClearableValueS
         return root.size();
     }
 
+    /**
+     * Retained for serializability - see {@link 
com.opensymphony.xwork2.ognl.OgnlValueStackTest#testSerializable}
+     */
+    private Object readResolve() {
+        // TODO: this should be done better
+        ActionContext ac = ActionContext.getContext();
+        Container cont = ac.getContainer();
+        XWorkConverter xworkConverter = cont.getInstance(XWorkConverter.class);
+        CompoundRootAccessor accessor = (CompoundRootAccessor) 
cont.getInstance(PropertyAccessor.class, CompoundRoot.class.getName());
+        TextProvider prov = cont.getInstance(TextProvider.class, "system");
+        SecurityMemberAccess sma = 
cont.getInstance(SecurityMemberAccess.class);
+        OgnlValueStack aStack = new OgnlValueStack(xworkConverter, accessor, 
prov, sma);
+        aStack.setOgnlUtil(cont.getInstance(OgnlUtil.class));
+        aStack.setRoot(xworkConverter, accessor, this.root, sma);
+        return aStack;
+    }
 
     public void clearContextValues() {
         //this is an OGNL ValueStack so the context will be an OgnlContext
diff --git 
a/core/src/main/java/com/opensymphony/xwork2/util/location/LocationImpl.java 
b/core/src/main/java/com/opensymphony/xwork2/util/location/LocationImpl.java
index 26b3072df..50a1809fc 100644
--- a/core/src/main/java/com/opensymphony/xwork2/util/location/LocationImpl.java
+++ b/core/src/main/java/com/opensymphony/xwork2/util/location/LocationImpl.java
@@ -202,6 +202,15 @@ public class LocationImpl implements Location, 
Serializable {
         return LocationUtils.toString(this);
     }
 
+    /**
+     * Ensure serialized unknown location resolve to {@link Location#UNKNOWN}.
+     *
+     * @return resolved location as object
+     */
+    private Object readResolve() {
+        return this.equals(Location.UNKNOWN) ? Location.UNKNOWN : this;
+    }
+
     private boolean testEquals(Object object1, Object object2) {
         if (object1 == object2) {
             return true;

Reply via email to