Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Won't Fix
-
2.0.12, 2.1.2
-
None
-
Patch
Description
While using an Result annotation on an action class with the result type of
JSONResult.class (from the struts2 jsonplugin) like the following code snippet
suggests:
@ParentPackage("default")
@Result(name=Action.SUCCESS,
value="",type=JSONResult.class,
params=
)
public class SomeAction implements Action
I came across the following exception:
Caught OgnlException while setting property 'location' on type 'com.googlecode.jsonplugin.JSONResult'.
com.opensymphony.xwork2.DefaultActionInvocation.createResult(DefaultActionInvocation.java:205)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:349)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:259)
...
After digging into the code from ClasspathPackageProvider I found the method
createResultConfig with the following code:
String defaultParam;
try
catch (Exception e)
{ // not sure why this happened, but let's just use a sensible choice defaultParam = "location"; } HashMap params = new HashMap();
if (configParams != null)
params.put(defaultParam, location);
return new ResultConfig.Builder((String) key, resultClass.getName()).addParams(params).build();
Because JSONResult does not define a field DEFAULT_PARAM, an entry called
"location" is inserted into the params HashMap with the empty string from
the value element of the Result annotation. This causes the exception later
because JSONResult does not define a method "setLocation".
I suspect it is not correct to try to set a property on a result class
which doesn't define the DEFAULT_PARAM field. I'll attach a patch to this
issue which fixed the bug for me. The patch was created against the latest
trunk version of ClasspathPackageProvider. If the patch finds its way into
the repository the same changes would have to be made in
ClasspathConfigurationProvider in the 2.0.* tree.