You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Volker Krebs (JIRA)" <ji...@apache.org> on 2013/11/26 10:50:37 UTC

[jira] [Commented] (WW-3603) XWorkMapPropertyAccessor always create new map entries

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

Volker Krebs commented on WW-3603:
----------------------------------

{code:xml}
<s:if test="#item.content[notExistingKey] != null">
	Prior to 2.3.16 it always returns true. 
</s:if>
{code}
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.


> XWorkMapPropertyAccessor always create new map entries
> ------------------------------------------------------
>
>                 Key: WW-3603
>                 URL: https://issues.apache.org/jira/browse/WW-3603
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.2.1
>            Reporter: Igor Evgrafov
>            Assignee: Lukasz Lenart
>             Fix For: 2.3.16
>
>         Attachments: 0001-WW-3603-Consider-value-of-CREATE_NULL_OBJECTS.patch
>
>
> 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}



--
This message was sent by Atlassian JIRA
(v6.1#6144)