You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by "Tim Moore (JIRA)" <de...@velocity.apache.org> on 2009/07/29 20:54:15 UTC

[jira] Created: (VELOCITY-730) Property references don't work with Google Collections ImmutableMap

Property references don't work with Google Collections ImmutableMap
-------------------------------------------------------------------

                 Key: VELOCITY-730
                 URL: https://issues.apache.org/jira/browse/VELOCITY-730
             Project: Velocity
          Issue Type: Bug
          Components: Engine
    Affects Versions: 1.6.1
            Reporter: Tim Moore


If you pass a map created using Google Collections ImmutableMap into a Velocity context, and try to access its values using "map.key" style property syntax, it fails to resolve.

I believe the problem is in MapGetExecutor:

http://svn.apache.org/viewvc/velocity/engine/tags/1.6.1/src/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java?view=co

Specifically, this code:

        Class [] interfaces = clazz.getInterfaces();
        for (int i = 0 ; i < interfaces.length; i++)
        {
            if (interfaces[i].equals(Map.class))
            {
...

The sneaky thing about ImmutableMap is that ImmutableMap.of(...) doesn't return an instance of ImmutableMap, but one of serveral subclasses optimized for however many items are in the map. These subclasses extend ImmutableMap but do not directly implement Map, so that code above fails to recognize them.

A simpler and more accurate way to tell whether the class implements Map, either directory or indirectly, is "if (Map.class.isAssignableFrom(clazz))..."

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Updated: (VELOCITY-730) Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)

Posted by "Tim Moore (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-730?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Tim Moore updated VELOCITY-730:
-------------------------------

    Summary: Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)  (was: Property references don't work with Google Collections ImmutableMap)

> Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-730
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-730
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.6.1
>            Reporter: Tim Moore
>
> If you pass a map created using Google Collections ImmutableMap into a Velocity context, and try to access its values using "map.key" style property syntax, it fails to resolve.
> I believe the problem is in MapGetExecutor:
> http://svn.apache.org/viewvc/velocity/engine/tags/1.6.1/src/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java?view=co
> Specifically, this code:
>         Class [] interfaces = clazz.getInterfaces();
>         for (int i = 0 ; i < interfaces.length; i++)
>         {
>             if (interfaces[i].equals(Map.class))
>             {
> ...
> The sneaky thing about ImmutableMap is that ImmutableMap.of(...) doesn't return an instance of ImmutableMap, but one of serveral subclasses optimized for however many items are in the map. These subclasses extend ImmutableMap but do not directly implement Map, so that code above fails to recognize them.
> A simpler and more accurate way to tell whether the class implements Map, either directory or indirectly, is "if (Map.class.isAssignableFrom(clazz))..."

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-730) Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-730?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12737287#action_12737287 ] 

Nathan Bubna commented on VELOCITY-730:
---------------------------------------

I attempted to reproduce this in a test case, but the map.key style worked just fine with a class structure designed to simulate that of ImmutableMap.  It worked, because Velocity 1.6+ will always look for a get(key) method if it fails to recognize that the object is a Map.  the MapGet/MapSetExecutors are merely optimizations.

So, while the map-specific executors are, indeed, missing things like ImmutableMap (i did confirm that), they are not the sole cause of your problem.  You should still be able to use ImmutableMaps.

> Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-730
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-730
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.6.1
>            Reporter: Tim Moore
>
> If you pass a map created using Google Collections ImmutableMap into a Velocity context, and try to access its values using "map.key" style property syntax, it fails to resolve.
> I believe the problem is in MapGetExecutor:
> http://svn.apache.org/viewvc/velocity/engine/tags/1.6.1/src/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java?view=co
> Specifically, this code:
>         Class [] interfaces = clazz.getInterfaces();
>         for (int i = 0 ; i < interfaces.length; i++)
>         {
>             if (interfaces[i].equals(Map.class))
>             {
> ...
> The sneaky thing about ImmutableMap is that ImmutableMap.of(...) doesn't return an instance of ImmutableMap, but one of serveral subclasses optimized for however many items are in the map. These subclasses extend ImmutableMap but do not directly implement Map, so that code above fails to recognize them.
> A simpler and more accurate way to tell whether the class implements Map, either directory or indirectly, is "if (Map.class.isAssignableFrom(clazz))..."

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-730) Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)

Posted by "Tim Moore (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-730?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12737796#action_12737796 ] 

Tim Moore commented on VELOCITY-730:
------------------------------------

And of course I didn't notice your previous comment where you already said that and linked to the issue! Thanks again.

> Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-730
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-730
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.6.1
>            Reporter: Tim Moore
>             Fix For: 1.7
>
>
> If you pass a map created using Google Collections ImmutableMap into a Velocity context, and try to access its values using "map.key" style property syntax, it fails to resolve.
> I believe the problem is in MapGetExecutor:
> http://svn.apache.org/viewvc/velocity/engine/tags/1.6.1/src/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java?view=co
> Specifically, this code:
>         Class [] interfaces = clazz.getInterfaces();
>         for (int i = 0 ; i < interfaces.length; i++)
>         {
>             if (interfaces[i].equals(Map.class))
>             {
> ...
> The sneaky thing about ImmutableMap is that ImmutableMap.of(...) doesn't return an instance of ImmutableMap, but one of serveral subclasses optimized for however many items are in the map. These subclasses extend ImmutableMap but do not directly implement Map, so that code above fails to recognize them.
> A simpler and more accurate way to tell whether the class implements Map, either directory or indirectly, is "if (Map.class.isAssignableFrom(clazz))..."

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-730) Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-730?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12737259#action_12737259 ] 

Nathan Bubna commented on VELOCITY-730:
---------------------------------------

Yeah, i can see that this would fail, though it's not because the subclasses don't themselves implement Map, but rather that ImmutableMap and descendants are implementors of ConcurrentMap which is a subinterface of Map.  We hit a similar problem in the ClassMap class recently (VELOCITY-689).  In this case, i think your solution is probably the best one, as it keeps it simple.

Thanks for reporting this.

> Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-730
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-730
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.6.1
>            Reporter: Tim Moore
>
> If you pass a map created using Google Collections ImmutableMap into a Velocity context, and try to access its values using "map.key" style property syntax, it fails to resolve.
> I believe the problem is in MapGetExecutor:
> http://svn.apache.org/viewvc/velocity/engine/tags/1.6.1/src/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java?view=co
> Specifically, this code:
>         Class [] interfaces = clazz.getInterfaces();
>         for (int i = 0 ; i < interfaces.length; i++)
>         {
>             if (interfaces[i].equals(Map.class))
>             {
> ...
> The sneaky thing about ImmutableMap is that ImmutableMap.of(...) doesn't return an instance of ImmutableMap, but one of serveral subclasses optimized for however many items are in the map. These subclasses extend ImmutableMap but do not directly implement Map, so that code above fails to recognize them.
> A simpler and more accurate way to tell whether the class implements Map, either directory or indirectly, is "if (Map.class.isAssignableFrom(clazz))..."

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Resolved: (VELOCITY-730) Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)

Posted by "Nathan Bubna (JIRA)" <de...@velocity.apache.org>.
     [ https://issues.apache.org/jira/browse/VELOCITY-730?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nathan Bubna resolved VELOCITY-730.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: 1.7

Ok, the flaw that kept MapGet/SetExecutor from handling the map.key syntax when the map class didn't directly implement Map has been resolved.

> Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-730
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-730
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.6.1
>            Reporter: Tim Moore
>             Fix For: 1.7
>
>
> If you pass a map created using Google Collections ImmutableMap into a Velocity context, and try to access its values using "map.key" style property syntax, it fails to resolve.
> I believe the problem is in MapGetExecutor:
> http://svn.apache.org/viewvc/velocity/engine/tags/1.6.1/src/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java?view=co
> Specifically, this code:
>         Class [] interfaces = clazz.getInterfaces();
>         for (int i = 0 ; i < interfaces.length; i++)
>         {
>             if (interfaces[i].equals(Map.class))
>             {
> ...
> The sneaky thing about ImmutableMap is that ImmutableMap.of(...) doesn't return an instance of ImmutableMap, but one of serveral subclasses optimized for however many items are in the map. These subclasses extend ImmutableMap but do not directly implement Map, so that code above fails to recognize them.
> A simpler and more accurate way to tell whether the class implements Map, either directory or indirectly, is "if (Map.class.isAssignableFrom(clazz))..."

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org


[jira] Commented: (VELOCITY-730) Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)

Posted by "Tim Moore (JIRA)" <de...@velocity.apache.org>.
    [ https://issues.apache.org/jira/browse/VELOCITY-730?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12737794#action_12737794 ] 

Tim Moore commented on VELOCITY-730:
------------------------------------

Thanks for the fix, Nathan. I think I see why the fallback "get" handling didn't work: there's a related issue with ClassMap (it doesn't see superinterfaces). I'll file a separate issue.

> Property references don't work with maps that implement Map indirectly (such as Google Collections ImmutableMap)
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: VELOCITY-730
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-730
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.6.1
>            Reporter: Tim Moore
>             Fix For: 1.7
>
>
> If you pass a map created using Google Collections ImmutableMap into a Velocity context, and try to access its values using "map.key" style property syntax, it fails to resolve.
> I believe the problem is in MapGetExecutor:
> http://svn.apache.org/viewvc/velocity/engine/tags/1.6.1/src/java/org/apache/velocity/runtime/parser/node/MapGetExecutor.java?view=co
> Specifically, this code:
>         Class [] interfaces = clazz.getInterfaces();
>         for (int i = 0 ; i < interfaces.length; i++)
>         {
>             if (interfaces[i].equals(Map.class))
>             {
> ...
> The sneaky thing about ImmutableMap is that ImmutableMap.of(...) doesn't return an instance of ImmutableMap, but one of serveral subclasses optimized for however many items are in the map. These subclasses extend ImmutableMap but do not directly implement Map, so that code above fails to recognize them.
> A simpler and more accurate way to tell whether the class implements Map, either directory or indirectly, is "if (Map.class.isAssignableFrom(clazz))..."

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org