Skip to content

Commit

Permalink
Merge pull request #745 from apache/WW-5339-cleanup
Browse files Browse the repository at this point in the history
WW-5339 Misc clean up in CompoundRootAccessor and OgnlValueStackTest
  • Loading branch information
lukaszlenart authored Sep 26, 2023
2 parents bb83a60 + 2b70b02 commit fde2b70
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
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;
Expand All @@ -31,7 +39,12 @@

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;
Expand Down Expand Up @@ -62,7 +75,7 @@ public String getSourceSetter(OgnlContext context, Object target, Object index)

private final static Logger LOG = LogManager.getLogger(CompoundRootAccessor.class);
private final static Class[] EMPTY_CLASS_ARRAY = new Class[0];
private static Map<MethodCall, Boolean> invalidMethods = new ConcurrentHashMap<>();
private static final Map<MethodCall, Boolean> invalidMethods = new ConcurrentHashMap<>();
private boolean devMode;

@Inject(StrutsConstants.STRUTS_DEVMODE)
Expand Down Expand Up @@ -127,7 +140,7 @@ public Object getProperty(Map context, Object target, Object name) throws OgnlEx
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;
Expand Down Expand Up @@ -190,26 +203,23 @@ public Object callMethod(Map context, Object target, String name, Object[] objec
}

SortedSet<String> 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);
Expand Down Expand Up @@ -321,9 +331,14 @@ public MethodCall(Class clazz, String name, Class[] args) {

@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) && Arrays.equals(mc.args, args);
}

@Override
Expand Down
Loading

0 comments on commit fde2b70

Please sign in to comment.