Struts 2
  1. Struts 2
  2. WW-3603

XWorkMapPropertyAccessor always create new map entries

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1
    • Fix Version/s: 2.3.16
    • Component/s: None
    • Labels:
      None

      Description

      XWorkMapPropertyAccessor uses "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" to check if it in create new objects mode.

                  if (result == null &&
                          context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null //BUG
                          &&  objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
                      Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);
      
                      try {
                          result = objectFactory.buildBean(valueClass, context);
                          map.put(key, result);
                      } catch (Exception exc) {
      
                      }
      
                  }
      

      However ParametersInterceptor uses ReflectionContextState.setCreatingNullObjects(contextMap, true\false); to turn this mode on and off. In result "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" is always true and result bean is always created.

                      Map<String, Object> contextMap = ac.getContextMap();
                      try {
                          ReflectionContextState.setCreatingNullObjects(contextMap, true);
                          ReflectionContextState.setDenyMethodExecution(contextMap, true);
                          ReflectionContextState.setReportingConversionErrors(contextMap, true);
      
                          ValueStack stack = ac.getValueStack();
                          setParameters(action, stack, parameters);
                      } finally {
                          ReflectionContextState.setCreatingNullObjects(contextMap, false);
                          ReflectionContextState.setDenyMethodExecution(contextMap, false);
                          ReflectionContextState.setReportingConversionErrors(contextMap, false);
                      }
      

        Activity

        Igor Evgrafov created issue -
        Igor Evgrafov made changes -
        Field Original Value New Value
        Description {{XWorkMapPropertyAccessor}} uses {{context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null}} to check if it in create new objects mode.
        {code}
                    if (result == null &&
                            context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null //BUG
                            && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
                        Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);

                        try {
                            result = objectFactory.buildBean(valueClass, context);
                            map.put(key, result);
                        } catch (Exception exc) {

                        }

                    }
        {code}

        However {{ParametersInterceptor}} uses {{ReflectionContextState.setCreatingNullObjects(contextMap, true\false);}} to turn this mode on and off. In result {{context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null}} is always true.

        {code:title=com.opensymphony.xwork2.interceptor.ParametersInterceptor}
                        Map<String, Object> contextMap = ac.getContextMap();
                        try {
                            ReflectionContextState.setCreatingNullObjects(contextMap, true);
                            ReflectionContextState.setDenyMethodExecution(contextMap, true);
                            ReflectionContextState.setReportingConversionErrors(contextMap, true);

                            ValueStack stack = ac.getValueStack();
                            setParameters(action, stack, parameters);
                        } finally {
                            ReflectionContextState.setCreatingNullObjects(contextMap, false);
                            ReflectionContextState.setDenyMethodExecution(contextMap, false);
                            ReflectionContextState.setReportingConversionErrors(contextMap, false);
                        }
        {code}
        XWorkMapPropertyAccessor uses "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" to check if it in create new objects mode.
        {code}
                    if (result == null &&
                            context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null //BUG
                            && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
                        Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);

                        try {
                            result = objectFactory.buildBean(valueClass, context);
                            map.put(key, result);
                        } catch (Exception exc) {

                        }

                    }
        {code}

        However ParametersInterceptor uses ReflectionContextState.setCreatingNullObjects(contextMap, true\false); to turn this mode on and off. In result {{context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null}} is always true.

        {code:title=com.opensymphony.xwork2.interceptor.ParametersInterceptor}
                        Map<String, Object> contextMap = ac.getContextMap();
                        try {
                            ReflectionContextState.setCreatingNullObjects(contextMap, true);
                            ReflectionContextState.setDenyMethodExecution(contextMap, true);
                            ReflectionContextState.setReportingConversionErrors(contextMap, true);

                            ValueStack stack = ac.getValueStack();
                            setParameters(action, stack, parameters);
                        } finally {
                            ReflectionContextState.setCreatingNullObjects(contextMap, false);
                            ReflectionContextState.setDenyMethodExecution(contextMap, false);
                            ReflectionContextState.setReportingConversionErrors(contextMap, false);
                        }
        {code}
        Igor Evgrafov made changes -
        Description XWorkMapPropertyAccessor uses "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" to check if it in create new objects mode.
        {code}
                    if (result == null &&
                            context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null //BUG
                            && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
                        Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);

                        try {
                            result = objectFactory.buildBean(valueClass, context);
                            map.put(key, result);
                        } catch (Exception exc) {

                        }

                    }
        {code}

        However ParametersInterceptor uses ReflectionContextState.setCreatingNullObjects(contextMap, true\false); to turn this mode on and off. In result {{context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null}} is always true.

        {code:title=com.opensymphony.xwork2.interceptor.ParametersInterceptor}
                        Map<String, Object> contextMap = ac.getContextMap();
                        try {
                            ReflectionContextState.setCreatingNullObjects(contextMap, true);
                            ReflectionContextState.setDenyMethodExecution(contextMap, true);
                            ReflectionContextState.setReportingConversionErrors(contextMap, true);

                            ValueStack stack = ac.getValueStack();
                            setParameters(action, stack, parameters);
                        } finally {
                            ReflectionContextState.setCreatingNullObjects(contextMap, false);
                            ReflectionContextState.setDenyMethodExecution(contextMap, false);
                            ReflectionContextState.setReportingConversionErrors(contextMap, false);
                        }
        {code}
        XWorkMapPropertyAccessor uses "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" to check if it in create new objects mode.
        ==================
                    if (result == null &&
                            context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null //BUG
                            && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
                        Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);

                        try {
                            result = objectFactory.buildBean(valueClass, context);
                            map.put(key, result);
                        } catch (Exception exc) {

                        }

                    }
        ==================

        However ParametersInterceptor uses ReflectionContextState.setCreatingNullObjects(contextMap, true\false); to turn this mode on and off. In result "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" is always true.

        ==================
                        Map<String, Object> contextMap = ac.getContextMap();
                        try {
                            ReflectionContextState.setCreatingNullObjects(contextMap, true);
                            ReflectionContextState.setDenyMethodExecution(contextMap, true);
                            ReflectionContextState.setReportingConversionErrors(contextMap, true);

                            ValueStack stack = ac.getValueStack();
                            setParameters(action, stack, parameters);
                        } finally {
                            ReflectionContextState.setCreatingNullObjects(contextMap, false);
                            ReflectionContextState.setDenyMethodExecution(contextMap, false);
                            ReflectionContextState.setReportingConversionErrors(contextMap, false);
                        }
        ==================
        Igor Evgrafov made changes -
        Description XWorkMapPropertyAccessor uses "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" to check if it in create new objects mode.
        ==================
                    if (result == null &&
                            context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null //BUG
                            && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
                        Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);

                        try {
                            result = objectFactory.buildBean(valueClass, context);
                            map.put(key, result);
                        } catch (Exception exc) {

                        }

                    }
        ==================

        However ParametersInterceptor uses ReflectionContextState.setCreatingNullObjects(contextMap, true\false); to turn this mode on and off. In result "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" is always true.

        ==================
                        Map<String, Object> contextMap = ac.getContextMap();
                        try {
                            ReflectionContextState.setCreatingNullObjects(contextMap, true);
                            ReflectionContextState.setDenyMethodExecution(contextMap, true);
                            ReflectionContextState.setReportingConversionErrors(contextMap, true);

                            ValueStack stack = ac.getValueStack();
                            setParameters(action, stack, parameters);
                        } finally {
                            ReflectionContextState.setCreatingNullObjects(contextMap, false);
                            ReflectionContextState.setDenyMethodExecution(contextMap, false);
                            ReflectionContextState.setReportingConversionErrors(contextMap, false);
                        }
        ==================
        XWorkMapPropertyAccessor uses "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" to check if it in create new objects mode.
        ==================
                    if (result == null &&
                            context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null //BUG
                            && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
                        Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);

                        try {
                            result = objectFactory.buildBean(valueClass, context);
                            map.put(key, result);
                        } catch (Exception exc) {

                        }

                    }
        ==================

        However ParametersInterceptor uses ReflectionContextState.setCreatingNullObjects(contextMap, true\false); to turn this mode on and off. In result "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" is always true and result bean is always created.

        ==================
                        Map<String, Object> contextMap = ac.getContextMap();
                        try {
                            ReflectionContextState.setCreatingNullObjects(contextMap, true);
                            ReflectionContextState.setDenyMethodExecution(contextMap, true);
                            ReflectionContextState.setReportingConversionErrors(contextMap, true);

                            ValueStack stack = ac.getValueStack();
                            setParameters(action, stack, parameters);
                        } finally {
                            ReflectionContextState.setCreatingNullObjects(contextMap, false);
                            ReflectionContextState.setDenyMethodExecution(contextMap, false);
                            ReflectionContextState.setReportingConversionErrors(contextMap, false);
                        }
        ==================
        Lukasz Lenart made changes -
        Fix Version/s 3.x [ 12319158 ]
        Lukasz Lenart made changes -
        Description XWorkMapPropertyAccessor uses "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" to check if it in create new objects mode.
        ==================
                    if (result == null &&
                            context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null //BUG
                            && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
                        Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);

                        try {
                            result = objectFactory.buildBean(valueClass, context);
                            map.put(key, result);
                        } catch (Exception exc) {

                        }

                    }
        ==================

        However ParametersInterceptor uses ReflectionContextState.setCreatingNullObjects(contextMap, true\false); to turn this mode on and off. In result "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" is always true and result bean is always created.

        ==================
                        Map<String, Object> contextMap = ac.getContextMap();
                        try {
                            ReflectionContextState.setCreatingNullObjects(contextMap, true);
                            ReflectionContextState.setDenyMethodExecution(contextMap, true);
                            ReflectionContextState.setReportingConversionErrors(contextMap, true);

                            ValueStack stack = ac.getValueStack();
                            setParameters(action, stack, parameters);
                        } finally {
                            ReflectionContextState.setCreatingNullObjects(contextMap, false);
                            ReflectionContextState.setDenyMethodExecution(contextMap, false);
                            ReflectionContextState.setReportingConversionErrors(contextMap, false);
                        }
        ==================
        XWorkMapPropertyAccessor uses "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" to check if it in create new objects mode.
        {code:java}
                    if (result == null &&
                            context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null //BUG
                            && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,false)) {
                        Class valueClass = objectTypeDeterminer.getElementClass(lastClass, lastProperty, key);

                        try {
                            result = objectFactory.buildBean(valueClass, context);
                            map.put(key, result);
                        } catch (Exception exc) {

                        }

                    }
        {code}

        However ParametersInterceptor uses ReflectionContextState.setCreatingNullObjects(contextMap, true\false); to turn this mode on and off. In result "context.get(ReflectionContextState.CREATE_NULL_OBJECTS) != null" is always true and result bean is always created.

        {code:java}
                        Map<String, Object> contextMap = ac.getContextMap();
                        try {
                            ReflectionContextState.setCreatingNullObjects(contextMap, true);
                            ReflectionContextState.setDenyMethodExecution(contextMap, true);
                            ReflectionContextState.setReportingConversionErrors(contextMap, true);

                            ValueStack stack = ac.getValueStack();
                            setParameters(action, stack, parameters);
                        } finally {
                            ReflectionContextState.setCreatingNullObjects(contextMap, false);
                            ReflectionContextState.setDenyMethodExecution(contextMap, false);
                            ReflectionContextState.setReportingConversionErrors(contextMap, false);
                        }
        {code}
        Joseph Walton made changes -
        Hide
        Joseph Walton added a comment -

        This issue causes all optional parameters to templates to be filled out as java.lang.Object@123abc for me. Patch attached, with tests, to pay attention when ReflectionContextState is used to set this to false.

        Show
        Joseph Walton added a comment - This issue causes all optional parameters to templates to be filled out as java.lang.Object@123abc for me. Patch attached, with tests, to pay attention when ReflectionContextState is used to set this to false .
        Lukasz Lenart made changes -
        Fix Version/s 2.3.17 [ 12324780 ]
        Fix Version/s 3.0 [ 12319158 ]
        Lukasz Lenart made changes -
        Fix Version/s 2.3.16 [ 12324546 ]
        Fix Version/s 2.3.17 [ 12324780 ]
        Lukasz Lenart made changes -
        Assignee Lukasz Lenart [ lukaszlenart ]
        Hide
        ASF subversion and git services added a comment -

        Commit 1532974 from Lukasz Lenart in branch 'struts2/trunk'
        [ https://svn.apache.org/r1532974 ]

        WW-3603 Prevents creating new map entries

        Show
        ASF subversion and git services added a comment - Commit 1532974 from Lukasz Lenart in branch 'struts2/trunk' [ https://svn.apache.org/r1532974 ] WW-3603 Prevents creating new map entries
        Hide
        Lukasz Lenart added a comment -

        Patch applied, thanks!

        Show
        Lukasz Lenart added a comment - Patch applied, thanks!
        Lukasz Lenart made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Hudson added a comment -

        FAILURE: Integrated in Struts2-JDK6 #812 (See https://builds.apache.org/job/Struts2-JDK6/812/)
        WW-3603 Prevents creating new map entries (lukaszlenart: rev 1532974)

        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java
        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessorTest.java
        Show
        Hudson added a comment - FAILURE: Integrated in Struts2-JDK6 #812 (See https://builds.apache.org/job/Struts2-JDK6/812/ ) WW-3603 Prevents creating new map entries (lukaszlenart: rev 1532974) /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessor.java /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/accessor/XWorkMapPropertyAccessorTest.java
        Hide
        Volker Krebs added a comment -
        <s:if test="#item.content[notExistingKey] != null">
        	Prior to 2.3.16 it always returns true. 
        </s:if>
        

        Prior to 2.3.16 a new map entry with key null and value '' is created when accesing a not existing key within a map (with OGNL).
        And #item.content[key] evaluates to #item.content[null] which returns '' and thus is not null.

        Show
        Volker Krebs added a comment - <s:if test= "#item.content[notExistingKey] != null" > Prior to 2.3.16 it always returns true. </s:if> Prior to 2.3.16 a new map entry with key null and value '' is created when accesing a not existing key within a map (with OGNL). And #item.content [key] evaluates to #item.content [null] which returns '' and thus is not null.
        Lukasz Lenart made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        919d 18h 47m 1 Lukasz Lenart 17/Oct/13 07:11
        Resolved Resolved Closed Closed
        52d 11h 9m 1 Lukasz Lenart 08/Dec/13 17:21

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            Igor Evgrafov
          • Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development