commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitri Blinov (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (JEXL-171) Map access operator does not work if key name clashes with map property name
Date Fri, 31 Jul 2015 06:38:04 GMT

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

Dmitri Blinov commented on JEXL-171:
------------------------------------

Oops, I have just bumped into a problem when accessing a Map property via '.' still returns
a property of the object implementing a Map and not a key-value from Map. I'm using custom
Uberspect implementation which overrides the default one with the follwing code:

{code}
   protected final List<ResolverType> resolvingOrder = Arrays.asList(
        JexlUberspect.ResolverType.MAP, 
        JexlUberspect.ResolverType.LIST, 
        JexlUberspect.ResolverType.CONTAINER,
        JexlUberspect.ResolverType.PROPERTY, 
        JexlUberspect.ResolverType.DUCK);
   }

   @Override
   public JexlPropertyGet getPropertyGet(Object obj, Object identifier) {
       return getPropertyGet(resolvingOrder, obj, identifier);
   }

   @Override
   public JexlPropertySet getPropertySet(final Object obj, final Object identifier, final
Object arg) {
       return getPropertySet(resolvingOrder, obj, identifier, arg);
   }
{code}

but that code just seems not to be used. After peeping into Interpeter.java I have found that
indeed the strategy for accessing methods is not taken from Uberspect but is constructed on
the fly:
{code}
        List<JexlUberspect.ResolverType> strategy = (node == null) || !(node.jjtGetParent()instanceof
ASTArrayAccess) ? JexlUberspect.POJO : JexlUberspect.MAP;
        JexlPropertyGet vg = uberspect.getPropertyGet(strategy, object, attribute);
{code}

I think it's a bad idea to break a rule of thumb that *a.b* should be equal to *a\["b"\]*.
If one wants to change the order for property resolution globally the custom Uberspect implementation
is right and sufficient way to do so, and combined with annotations for particular objects
we can provide virtually any desired flexibility

> Map access operator does not work if key name clashes with map property name
> ----------------------------------------------------------------------------
>
>                 Key: JEXL-171
>                 URL: https://issues.apache.org/jira/browse/JEXL-171
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.0
>            Reporter: Dmitri Blinov
>            Assignee: Henri Biestro
>            Priority: Critical
>             Fix For: 3.0
>
>
> The following example returns *false*, according to documentation should return *2*.
> i = new ("java.util.HashMap"); i.a = 1; i["empty"] = 2; i["empty"] 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message