Velocity
  1. Velocity
  2. VELOCITY-109

failed to call overloaded method in foreach loop when item changes class type

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3-rc1
    • Fix Version/s: None
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Operating System: Windows XP
      Platform: PC

      Description

      1 create a class with two overloaded methods like
      public class Helper {
      public String getFoo(Integer v)

      { return "int "+v; }

      public String getFoo(String v)

      { return "str "+v; }

      }
      2. put an instance of Helper and a collection containing two items of
      different types
      col = new ArrayList();
      col.add(new Integer(100));
      col.add("STRVALUE");
      ctx.put("helper", new Helper());
      ctx.put("col", col);
      3. in a template, do
      #foreach ( $item in $col )
      ${helper.getFoo($item)
      #end
      4. evaluate the template and you should see
      int 100
      ${helper.getFoo($item)

      The error: the second item should invoke getFoo(String) but it apparently
      fails and causing the invocation failure.

        Activity

        Hide
        Henning Schmiedehausen added a comment -

        Close all resolved issues for older releases.

        Show
        Henning Schmiedehausen added a comment - Close all resolved issues for older releases.
        Hide
        Will Glass-Husain added a comment -

        Thanks for reporting this. The problem was that the parsed node for the
        method call (containing the location in the template, the method name, and the
        param name) was used as a key for the method cache. Changed this to also
        include the param classes as the key for the method cache. Consequently if
        the param classes change during the foreach, a new method is retrieved.

        Fixed in Revision # 149378

        Show
        Will Glass-Husain added a comment - Thanks for reporting this. The problem was that the parsed node for the method call (containing the location in the template, the method name, and the param name) was used as a key for the method cache. Changed this to also include the param classes as the key for the method cache. Consequently if the param classes change during the foreach, a new method is retrieved. Fixed in Revision # 149378
        Hide
        Geir Magnusson Jr added a comment -

        yep - thanks for the good example

        Show
        Geir Magnusson Jr added a comment - yep - thanks for the good example

          People

          • Assignee:
            Unassigned
            Reporter:
            Hacking Bear
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development