Velocity
  1. Velocity
  2. VELOCITY-651

Velocity 1.6 does not work with Struts MessageTool 1.4

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6
    • Fix Version/s: 1.6.1, 1.7
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Velocity 1.6, Struts MessageTool 1.4, Struts 1.2.9, Java 1.6_10

      Description

      The org.apache.velocity.tools.struts.MessageTool of VelocityTools version 1.4 contains a method signature of String get(String key, Object args[]).

      With Velocity 1.5, one could use a Struts resource, such as
      test1=this is a

      {0}

      in a Velocity template with
      $text.get('test1', ['TEST'])

      that would render the text
      this is a TEST

      Unfortunately, since the released version 1.6 I get the following exception:
      Invocation of method 'get' in class org.apache.velocity.tools.struts.MessageTool threw exception java.lang.IllegalArgumentException: wrong number of arguments at ..

      The setting of the property runtime.references.strict has no influence.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        11h 24m 1 Nathan Bubna 03/Dec/08 22:47
        Mark Thomas made changes -
        Workflow Default workflow, editable Closed status [ 12551660 ] jira [ 12552536 ]
        Mark Thomas made changes -
        Workflow jira [ 12447529 ] Default workflow, editable Closed status [ 12551660 ]
        Hide
        Stephan Schmid added a comment -

        Now, it works as expected
        Thanks for your great work!

        Show
        Stephan Schmid added a comment - Now, it works as expected Thanks for your great work!
        Hide
        Nathan Bubna added a comment -

        Stephan, if you would like, here's an update build with the fix for this in place:

        http://people.apache.org/~nbubna/velocity/engine/1.6.1-dev/

        Show
        Nathan Bubna added a comment - Stephan, if you would like, here's an update build with the fix for this in place: http://people.apache.org/~nbubna/velocity/engine/1.6.1-dev/
        Nathan Bubna made changes -
        Field Original Value New Value
        Fix Version/s 1.7 [ 12313453 ]
        Fix Version/s 1.6.1 [ 12313544 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Nathan Bubna added a comment -

        Alright, the fix is in the trunk. I'll also create a 1.6.x branch so this can go in a 1.6.1 release.

        Show
        Nathan Bubna added a comment - Alright, the fix is in the trunk. I'll also create a 1.6.x branch so this can go in a 1.6.1 release.
        Hide
        Nathan Bubna added a comment -

        Quite the nasty little reflection bug you've found. This will definitely warrant a 1.6.1 release. I really wish this had been discovered two weeks ago. Oh well...

        There are two underlying problems. First, MethodMap is bizarrely matching a get(String,List) call to the get(String,String,Object[]) method. That's the worst part. Subsequent to that, though, VelMethodImpl-thinking this is a vararg call there are only 2 args for a 3 arg method that ends with an array arg-mishandles the arguments, trying to pass too few in. I've fixed this latter bug, but i'm still working on the former one.

        just fyi...

        Show
        Nathan Bubna added a comment - Quite the nasty little reflection bug you've found. This will definitely warrant a 1.6.1 release. I really wish this had been discovered two weeks ago. Oh well... There are two underlying problems. First, MethodMap is bizarrely matching a get(String,List) call to the get(String,String,Object[]) method. That's the worst part. Subsequent to that, though, VelMethodImpl- thinking this is a vararg call there are only 2 args for a 3 arg method that ends with an array arg -mishandles the arguments, trying to pass too few in. I've fixed this latter bug, but i'm still working on the former one. just fyi...
        Hide
        Stephan Schmid added a comment - - edited

        Well, at least under Velocity 1.4 and 1.5 the [] notation worked for arrays.
        This notation is also shown in a corresponding example at http://velocity.apache.org/tools/releases/1.4/struts/MessageTool.html
        After looking at it a little more, the MessageTool contains also an overloaded method with get(String, List), so it should work anyway...

        Following, the interesting part of the stack trace:

        java.lang.IllegalArgumentException: wrong number of arguments
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389)
        at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378)
        at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270)
        at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:252)
        at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:339)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
        at org.apache.velocity.runtime.directive.Parse.render(Parse.java:262)
        at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:176)
        at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
        at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:106)
        at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
        at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:106)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
        at org.apache.velocity.runtime.directive.Parse.render(Parse.java:262)
        at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:176)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
        at org.apache.velocity.Template.merge(Template.java:328)

        Greetings,
        Stephan

        Show
        Stephan Schmid added a comment - - edited Well, at least under Velocity 1.4 and 1.5 the [] notation worked for arrays. This notation is also shown in a corresponding example at http://velocity.apache.org/tools/releases/1.4/struts/MessageTool.html After looking at it a little more, the MessageTool contains also an overloaded method with get(String, List), so it should work anyway... Following, the interesting part of the stack trace: java.lang.IllegalArgumentException: wrong number of arguments at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:389) at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:378) at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:270) at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:252) at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:339) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.runtime.directive.Parse.render(Parse.java:262) at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:176) at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:106) at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:106) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.runtime.directive.Parse.render(Parse.java:262) at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:176) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336) at org.apache.velocity.Template.merge(Template.java:328) Greetings, Stephan
        Hide
        Nathan Bubna added a comment -

        Hmm. Well, the actual method being called by $text.get('test1', ['TEST']) would be get(String, List), since [] creates an ArrayList, not an array.

        Still, i'll look into this. Can you get me more of the stack trace for that exception?

        Show
        Nathan Bubna added a comment - Hmm. Well, the actual method being called by $text.get('test1', ['TEST'] ) would be get(String, List), since [] creates an ArrayList, not an array. Still, i'll look into this. Can you get me more of the stack trace for that exception?
        Stephan Schmid created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Stephan Schmid
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development