[struts] 01/01: WW-5339 Clean up OgnlValueStackTest
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5339-cleanup in repository https://gitbox.apache.org/repos/asf/struts.git commit 7bd31cf3159045f3dc285bfde008397a8ebae21f Author: Kusal Kithul-Godage AuthorDate: Wed Aug 30 13:56:25 2023 +1000 WW-5339 Clean up OgnlValueStackTest --- .../xwork2/ognl/OgnlValueStackTest.java| 245 +++-- 1 file changed, 75 insertions(+), 170 deletions(-) diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java index f8e22dbf9..5f0ac5b26 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java @@ -48,13 +48,14 @@ import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.struts2.StrutsConstants; import org.apache.struts2.StrutsException; import org.apache.struts2.config.DefaultPropertiesProvider; +import org.apache.struts2.config.StrutsXmlConfigurationProvider; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -84,14 +85,13 @@ public class OgnlValueStackTest extends XWorkTestCase { private OgnlUtil ognlUtil; +private OgnlValueStack vs; + @Override public void setUp() throws Exception { super.setUp(); ognlUtil = container.getInstance(OgnlUtil.class); -} - -private OgnlValueStack createValueStack() { -return createValueStack(true); +vs = createValueStack(true); } private OgnlValueStack createValueStack(boolean allowStaticFieldAccess) { @@ -134,7 +134,6 @@ public class OgnlValueStackTest extends XWorkTestCase { Map expr1 = new LinkedHashMap(); expr1.put("expr1", "'expr1value'"); -OgnlValueStack vs = createValueStack(); vs.setExprOverrides(expr1); assertEquals(vs.findValue("expr1"), "expr1value"); @@ -150,8 +149,6 @@ public class OgnlValueStackTest extends XWorkTestCase { public void testArrayAsString() { -OgnlValueStack vs = createValueStack(); - Dog dog = new Dog(); dog.setAge(12); dog.setName("Rover"); @@ -167,7 +164,6 @@ public class OgnlValueStackTest extends XWorkTestCase { } private void testValuesFromContextAreConverted(String propertyName) { -final OgnlValueStack vs = createValueStack(); final String propertyValue = "Rover"; vs.getContext().put(propertyName, new String[]{propertyValue}); @@ -180,7 +176,6 @@ public class OgnlValueStackTest extends XWorkTestCase { } private void testNullValueFromContextGetsConverted(String propertyName) { -final OgnlValueStack vs = createValueStack(); final String propertyValue = null; vs.getContext().put(propertyName, propertyValue); @@ -188,8 +183,6 @@ public class OgnlValueStackTest extends XWorkTestCase { } public void testFailOnException() { -OgnlValueStack vs = createValueStack(); - Dog dog = new Dog(); vs.push(dog); try { @@ -202,8 +195,6 @@ public class OgnlValueStackTest extends XWorkTestCase { public void testFailOnErrorOnInheritedProperties() { //this shuld not fail as the property is defined on a parent class -OgnlValueStack vs = createValueStack(); - Foo foo = new Foo(); BarJunior barjr = new BarJunior(); foo.setBarJunior(barjr); @@ -215,8 +206,6 @@ public class OgnlValueStackTest extends XWorkTestCase { public void testSuccessFailOnErrorOnInheritedPropertiesWithMethods() { //this shuld not fail as the property is defined on a parent class -OgnlValueStack vs = createValueStack(); - Foo foo = new Foo(); BarJunior barjr = new BarJunior(); foo.setBarJunior(barjr); @@ -227,8 +216,6 @@ public class OgnlValueStackTest extends XWorkTestCase { } public void testFailFailOnErrorOnInheritedPropertiesWithMethods() { -OgnlValueStack vs = createValueStack(); - Foo foo = new Foo(); BarJunior barjr = new BarJunior(); foo.setBarJunior(barjr); @@ -243,8 +230,6 @@ public class OgnlValueStackTest extends XWorkTestCase { } public void testFailOnMissingProperty() { -OgnlValueStack vs = createValueStack(); - Dog dog = new Dog(); vs.push(dog); try { @@ -266,7 +251,6 @@ public class OgnlValueStackTest extends XWorkTestCase { } private void testLogMissingProperties(boolean logMissingProperties) { -OgnlValueStack vs = createValueStack(); vs.setLo
[struts] branch WW-5339-cleanup created (now 7bd31cf31)
This is an automated email from the ASF dual-hosted git repository. kusal pushed a change to branch WW-5339-cleanup in repository https://gitbox.apache.org/repos/asf/struts.git at 7bd31cf31 WW-5339 Clean up OgnlValueStackTest This branch includes the following new commits: new 7bd31cf31 WW-5339 Clean up OgnlValueStackTest The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
[struts] branch WW-5339-cleanup updated: WW-5339 Misc clean up in CompoundRootAccessor
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch WW-5339-cleanup in repository https://gitbox.apache.org/repos/asf/struts.git The following commit(s) were added to refs/heads/WW-5339-cleanup by this push: new 2b70b024b WW-5339 Misc clean up in CompoundRootAccessor 2b70b024b is described below commit 2b70b024bd3297583c4aa45474024d21c39de866 Author: Kusal Kithul-Godage AuthorDate: Mon Aug 28 13:42:41 2023 +1000 WW-5339 Misc clean up in CompoundRootAccessor --- .../xwork2/ognl/accessor/CompoundRootAccessor.java | 47 ++ 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java index 8d83e3331..25bedba66 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java +++ b/core/src/main/java/com/opensymphony/xwork2/ognl/accessor/CompoundRootAccessor.java @@ -22,7 +22,15 @@ import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.ognl.OgnlValueStack; import com.opensymphony.xwork2.util.CompoundRoot; import com.opensymphony.xwork2.util.ValueStack; -import ognl.*; +import ognl.ClassResolver; +import ognl.MethodAccessor; +import ognl.MethodFailedException; +import ognl.NoSuchPropertyException; +import ognl.Ognl; +import ognl.OgnlContext; +import ognl.OgnlException; +import ognl.OgnlRuntime; +import ognl.PropertyAccessor; import org.apache.commons.lang3.BooleanUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -31,7 +39,12 @@ import org.apache.struts2.StrutsException; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import static java.lang.String.format; @@ -62,7 +75,7 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C private final static Logger LOG = LogManager.getLogger(CompoundRootAccessor.class); private final static Class[] EMPTY_CLASS_ARRAY = new Class[0]; -private static Map invalidMethods = new ConcurrentHashMap<>(); +private static final Map invalidMethods = new ConcurrentHashMap<>(); private boolean devMode; @Inject(StrutsConstants.STRUTS_DEVMODE) @@ -127,7 +140,7 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C return root.cutStack(index); } else if (name instanceof String) { if ("top".equals(name)) { -if (root.size() > 0) { +if (!root.isEmpty()) { return root.get(0); } else { return null; @@ -190,26 +203,23 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C } SortedSet set = new TreeSet<>(); -StringBuffer sb = new StringBuffer(); -for (PropertyDescriptor pd : descriptors.values()) { +for (PropertyDescriptor pd : descriptors.values()) { +StringBuilder sb = new StringBuilder(); sb.append(pd.getName()).append(": "); + int padding = maxSize - pd.getName().length(); for (int i = 0; i < padding; i++) { sb.append(" "); } sb.append(pd.getPropertyType().getName()); set.add(sb.toString()); - -sb = new StringBuffer(); } -sb = new StringBuffer(); -for (Object aSet : set) { -String s = (String) aSet; -sb.append(s).append("\n"); +StringBuilder sb = new StringBuilder(); +for (String aSet : set) { +sb.append(aSet).append("\n"); } - return sb.toString(); } catch (IntrospectionException | OgnlException e) { LOG.debug("Got exception in callMethod", e); @@ -321,9 +331,14 @@ public class CompoundRootAccessor implements PropertyAccessor, MethodAccessor, C @Override public boolean equals(Object obj) { -MethodCall mc = (CompoundRootAccessor.MethodCall) obj; - -return (mc.clazz.equals(clazz) && mc.name.equals(name) && Arrays.equals(mc.args, args)); +if (this == obj) { +return true; +} +if (!(obj instanceof MethodCall)) { +return false; +} +MethodCall mc = (MethodCall) obj; +return mc.clazz.equals(clazz) && mc.name.equals(name
[struts] branch WW-5342-default-package updated (4a5edf640 -> ff79c1b04)
This is an automated email from the ASF dual-hosted git repository. kusal pushed a change to branch WW-5342-default-package in repository https://gitbox.apache.org/repos/asf/struts.git from 4a5edf640 WW-5342 Ban use of default package add ff79c1b04 WW-5342 Implement default off option No new revisions were added by this update. Summary of changes: .../java/com/opensymphony/xwork2/ognl/OgnlUtil.java | 10 ++ .../com/opensymphony/xwork2/ognl/OgnlValueStack.java | 1 + .../xwork2/ognl/SecurityMemberAccess.java | 19 +++ .../main/java/org/apache/struts2/StrutsConstants.java | 1 + .../xwork2/ognl/SecurityMemberAccessTest.java | 10 ++ 5 files changed, 37 insertions(+), 4 deletions(-)
[struts] branch WW-5342-default-package updated (ff79c1b04 -> bfe1f8cd3)
This is an automated email from the ASF dual-hosted git repository. kusal pushed a change to branch WW-5342-default-package in repository https://gitbox.apache.org/repos/asf/struts.git from ff79c1b04 WW-5342 Implement default off option add bfe1f8cd3 WW-5342 Optimise package exclusion check No new revisions were added by this update. Summary of changes: .../main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)