Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-2170

ObjectFactory.buildResult not correctly configuring Result instance properties

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.9
    • 2.1.1
    • Core Actions
    • None
    • WIndows Server 2003

    • Patch

    Description

      Hi, I think I have stumbled across a bug in the ObjectFactory.

      ObjectFactory.buildResult() invokes OgnlUtil.setProperties(resultConfig.getParams(), result, extraContext, true) to populate a Result instance with a parameter map. In addition, the call to OgnlUtil.setProperties forces exceptions to be thrown when necessary, by setting the last parameter in the method call to 'true'.

      If an exception is thrown, it is caught by the ObjectFactory and logged with a level of DEBUG. Further, in the ObjectFactory.buildResult() method the following comment appears: "ognl exceptions could be thrown and be ok if, for example, the result uses parameters in ways other than as properties for the result object."

      However, throwing exceptions is not ok. The Ognl.setProperties method will stop execution if an exception is thrown. As such, it is possible that not all properties specified in the ResultConfig parameter map will be set on the Result instance.

      For example, I am trying to set a property on a JSONResult class. However, the ResultConfig parameter map has a 'location' property in addition to the property in my Result action annotation. (I havne't tracked down where this location is being set in the ResultConfig). The 'location' property is the first thing that OgnlUtils tries to set and an error is thrown. Loop iteration stops, and the "enableSMD" property in the params map is ignored and the Result class is incorrectly configured.

      Here is my Action class:
      @Result(name = "success", value = "", type = JSONResult.class, params =

      {"enableSMD", "true"}

      )
      public class JsonAction extends ActionSupport {

      @SMDMethod
      public String getName(String client)

      { return "testName"; }

      }

      If all you want to do is log an erroneous attempt to set a property, why are you throwing exceptions? The OgnlUtil.internalSetProperty() method will do that for you if it configured not to throw exceptions.

      Attachments

        1. ww-2170.patch
          4 kB
          Aaron Brown
        2. ww-2170.patch
          22 kB
          Aaron Brown
        3. ww-2170.patch
          3 kB
          Aaron Brown

        Activity

          People

            mrdon Donald J. Brown
            aaronbrown Aaron Brown
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: