You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Lasantha Pambagoda (JIRA)" <ji...@apache.org> on 2009/03/24 14:35:02 UTC

[jira] Commented: (WW-2848) Exception while using @Result annotation with result type which doesn't define a default parameter

    [ https://issues.apache.org/struts/browse/WW-2848?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45767#action_45767 ] 

Lasantha Pambagoda commented on WW-2848:
----------------------------------------

This is still happening in 2.1.6 version and fix is not found in the code (code is same as the before the fix by  Lars Martensen)

> 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
>             Fix For: 2.1.3
>
>         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.