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 79ffc86b68c94cdf8e2f7b4526d415ab1f2ec9c7
Author: Kusal Kithul-Godage <g...@kusal.io>
AuthorDate: Thu Aug 31 23:56:02 2023 +1000

    WW-5343 Delete unused code and consolidate constructors
---
 .../opensymphony/xwork2/ognl/OgnlValueStack.java   | 36 ++++++++---------
 .../xwork2/util/location/LocationImpl.java         | 47 +++++++++-------------
 2 files changed, 35 insertions(+), 48 deletions(-)

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 01b6af81d..69802c5c2 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java
@@ -21,7 +21,6 @@ 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;
@@ -34,7 +33,6 @@ 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;
@@ -77,13 +75,26 @@ public class OgnlValueStack implements Serializable, 
ValueStack, ClearableValueS
     private boolean devMode;
     private boolean logMissingProperties;
 
+    protected OgnlValueStack(ValueStack vs,
+                             XWorkConverter xworkConverter,
+                             CompoundRootAccessor accessor,
+                             TextProvider prov,
+                             boolean allowStaticFieldAccess) {
+        setRoot(xworkConverter,
+                accessor,
+                vs != null ? new CompoundRoot(vs.getRoot()) : new 
CompoundRoot(),
+                allowStaticFieldAccess);
+        if (prov != null) {
+            push(prov);
+        }
+    }
+
     protected OgnlValueStack(XWorkConverter xworkConverter, 
CompoundRootAccessor accessor, TextProvider prov, boolean 
allowStaticFieldAccess) {
-        setRoot(xworkConverter, accessor, new CompoundRoot(), 
allowStaticFieldAccess);
-        push(prov);
+        this(null, xworkConverter, accessor, prov, allowStaticFieldAccess);
     }
 
     protected OgnlValueStack(ValueStack vs, XWorkConverter xworkConverter, 
CompoundRootAccessor accessor, boolean allowStaticFieldAccess) {
-        setRoot(xworkConverter, accessor, new CompoundRoot(vs.getRoot()), 
allowStaticFieldAccess);
+        this(vs, xworkConverter, accessor, null, allowStaticFieldAccess);
     }
 
     @Inject
@@ -464,21 +475,6 @@ public class OgnlValueStack implements Serializable, 
ValueStack, ClearableValueS
         return root.size();
     }
 
-    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");
-        final boolean allowStaticField = 
BooleanUtils.toBoolean(cont.getInstance(String.class, 
StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS));
-        OgnlValueStack aStack = new OgnlValueStack(xworkConverter, accessor, 
prov, allowStaticField);
-        aStack.setOgnlUtil(cont.getInstance(OgnlUtil.class));
-        aStack.setRoot(xworkConverter, accessor, this.root, allowStaticField);
-
-        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 298b34b3f..26b3072df 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
@@ -37,7 +37,7 @@ public class LocationImpl implements Location, Serializable {
     private final int line;
     private final int column;
     private final String description;
-    
+
     // Package private: outside this package, use Location.UNKNOWN.
     static final LocationImpl UNKNOWN = new LocationImpl(null, null, -1, -1);
 
@@ -71,16 +71,16 @@ public class LocationImpl implements Location, Serializable 
{
         }
         this.description = StringUtils.trimToNull(description);
     }
-    
+
     /**
      * Copy constructor.
-     * 
+     *
      * @param location the location to be copied
      */
     public LocationImpl(Location location) {
         this(location.getDescription(), location.getURI(), 
location.getLineNumber(), location.getColumnNumber());
     }
-    
+
     /**
      * Create a location from an existing one, but with a different description
      *
@@ -90,14 +90,14 @@ public class LocationImpl implements Location, Serializable 
{
     public LocationImpl(String description, Location location) {
         this(description, location.getURI(), location.getLineNumber(), 
location.getColumnNumber());
     }
-    
+
     /**
      * Obtain a <code>LocationImpl</code> from a {@link Location}. If 
<code>location</code> is
      * already a <code>LocationImpl</code>, it is returned, otherwise it is 
copied.
      * <p>
      * This method is useful when an immutable and serializable location is 
needed, such as in locatable
      * exceptions.
-     * 
+     *
      * @param location the location
      * @return an immutable and serializable version of <code>location</code>
      */
@@ -110,19 +110,19 @@ public class LocationImpl implements Location, 
Serializable {
             return new LocationImpl(location);
         }
     }
-    
+
     /**
      * Get the description of this location
-     * 
+     *
      * @return the description (can be <code>null</code>)
      */
     public String getDescription() {
         return this.description;
     }
-    
+
     /**
      * Get the URI of this location
-     * 
+     *
      * @return the URI (<code>null</code> if unknown).
      */
     public String getURI() {
@@ -131,22 +131,22 @@ public class LocationImpl implements Location, 
Serializable {
 
     /**
      * Get the line number of this location
-     * 
+     *
      * @return the line number (<code>-1</code> if unknown)
      */
     public int getLineNumber() {
         return this.line;
     }
-    
+
     /**
      * Get the column number of this location
-     * 
+     *
      * @return the column number (<code>-1</code> if unknown)
      */
     public int getColumnNumber() {
         return this.column;
     }
-    
+
     /**
      * @param padding The amount of lines before and after the error to include
      * @return a source code snippet with the default padding
@@ -184,33 +184,24 @@ public class LocationImpl implements Location, 
Serializable {
                    && testEquals(this.uri, other.getURI())
                    && testEquals(this.description, other.getDescription());
         }
-        
+
         return false;
     }
-    
+
     @Override
     public int hashCode() {
         int hash = line ^ column;
         if (uri != null) hash ^= uri.hashCode();
         if (description != null) hash ^= description.hashCode();
-        
+
         return hash;
     }
-    
+
     @Override
     public String toString() {
         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