-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WW-5336 Deprecate OgnlTool #735
Conversation
fdf00c1
to
23abcf7
Compare
Await merge of #731 first |
518d2ac
to
740cb68
Compare
740cb68
to
35b0a68
Compare
@@ -50,32 +61,30 @@ public class StrutsUtil { | |||
|
|||
protected HttpServletRequest request; | |||
protected HttpServletResponse response; | |||
protected Map<String, Class> classes = new Hashtable<>(); | |||
protected OgnlTool ognl; | |||
protected Map<String, Class<?>> classes = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is constructed per request thread so I don't believe we need concurrency handling here
public Object bean(Object name) throws Exception { | ||
String className = name.toString(); | ||
Class<?> clazz = classes.get(className); | ||
if (clazz == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using #computeIfAbsent here would change the exception handling semantics so I've forgone it
@@ -124,6 +123,17 @@ public Object findValue(String expression, String className) throws ClassNotFoun | |||
return stack.findValue(expression, Class.forName(className)); | |||
} | |||
|
|||
public Object findValue(String expr, Object context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copied this here from OgnlTool
return ognl.getValue(expr, ActionContext.getContext().getContextMap(), context); | ||
} catch (OgnlException e) { | ||
if (e.getReason() instanceof SecurityException) { | ||
LOG.error(format("Could not evaluate this expression due to security constraints: [{0}]", expr), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed broken logging
selectedItems.add(i); | ||
} | ||
} | ||
public List<ListEntry> makeSelectList(String selectedList, String list, String listKey, String listValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed cognitive complexity and readability
@@ -198,7 +198,7 @@ | |||
<bean type="ognl.MethodAccessor" name="com.opensymphony.xwork2.util.CompoundRoot" | |||
class="com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor"/> | |||
|
|||
<bean class="org.apache.struts2.views.jsp.ui.OgnlTool"/> | |||
<bean class="org.apache.struts2.views.jsp.ui.OgnlTool"/> <!-- Deprecated since 6.3.0 --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to put the comment before the bean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amended - I tend to favour the same line as sometimes comments can become detached from their intended line in highly concurrent teams
|
||
List<ListEntry> listMade = strutsUtil.makeSelectList("#mySelectedList", "#myList", null, null); | ||
|
||
assertEquals(listMade.size(), 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for assertEquals, the expected value should be the first argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems all the assertions in this class are mis-ordered, I've amended the ones I've touched :)
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Hope this is the last change and I can prepare another RC or even test build and call for vote :) |
I opened 2 more security enhancement cards that I intend to work on next week or the week after. Up to you whether you want these in 6.3.0 or a later release |
WW-5336
I couldn't see any value in retaining OgnlTool as its own class so I've deprecated it and merged the method into StrutsUtil.