struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lars Martensen (JIRA)" <j...@apache.org>
Subject [jira] Updated: (WW-2848) Exception while using @Result annotation with result type which doesn't define a default parameter
Date Fri, 24 Oct 2008 16:59:37 GMT

     [ https://issues.apache.org/struts/browse/WW-2848?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Lars Martensen updated WW-2848:
-------------------------------

    Attachment: patch_20081024.diff

> Exception while using @Result annotation with result type which doesn't define a default
parameter
> --------------------------------------------------------------------------------------------------
>
>                 Key: WW-2848
>                 URL: https://issues.apache.org/struts/browse/WW-2848
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - CodeBehind
>    Affects Versions: 2.0.12, 2.1.2
>            Reporter: Lars Martensen
>         Attachments: patch_20081024.diff
>
>
> 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={"noCache", "true", "root", "result"}
> )
> 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 {
>      defaultParam = (String) resultClass.getField("DEFAULT_PARAM").get(null);
>   } 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.putAll(configParams);
>   }
>   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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message