Velocity
  1. Velocity
  2. VELOCITY-701

migrating from 1.4 to 1.6.1 iteration over a List no longer works

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.1
    • Fix Version/s: 1.6.2, 1.7, 2.x
    • Component/s: Engine
    • Labels:
      None
    • Environment:
      Linux, Sun Java 1.5

      Description

      I have a template that references a List returned by a method on an Enum. The method is defined as an abstract member of the enum. This used to work on 1.4, but doesn't work on 1.6.1 I'm able to get it to work on 1.6.1 by changing the abstract method to a regular method of the Enum, which is then overridden by each instance of the enum. Here's the code that doesn't work.

      Again, it seems to be the abstract modifier, becuase if I change that method to something like

      public List getMyList()

      { return new ArrayList(); }

      And then just override it in my enum instances, everything works fine.

      public enum Thing {

      NUMBER_ONE( ){
      public List<String> getInnerThings() {
      //initialize innerThings if this is first time
      if ( this.innerThings == null )

      { innerThings = new ArrayList<String>(); innerThings.add( "blah blah" ); innerThings.add("blah blah" ); }
      return innerThings;
      }
      },
      NUMBER_TWO( ){
      public List<String> getinnerThings() {
      //initialize innerThings if this is first time
      if ( this.innerThings == null ) { innerThings = new ArrayList<String>(); innerThings.add( "blah blah" ); innerThings.add("blah blah" ); }

      return innerThings;

      }
      },
      NUMBER_THREE( ){
      public List<String> getinnerThings() {
      if ( this.innerThings == null )

      { innerThings = new ArrayList<String>(); innerThings.add( "blah blah" ); innerThings.add("blah blah" ); }

      return innerThings;

      }
      };

      List<String> innerThings;

      //This was an abstract method, but Velocity 1.6 quite working with it.
      public abstract List<String> getinnerThings();

      }

        Activity

        Hide
        Nathan Bubna added a comment -

        The trouble seems to be with abstract public methods declared in abstract classes and implemented in non-public classes. An enum class with an abstract public method shows this, but it also happens with things like:

        public abstract Foo

        { public abstract String getBar(); }

        Foo foo = new Foo() { public String getBar()

        { return "bar"; }

        };

        I think this worked in Velocity 1.4 because the ClassMap implementation was based off of Class.getMethods, whereas it was changed to Class.getDeclaredMethods in 1.5 to speed things up. Calling getDeclaredMethods on Foo doesn't return getBar, which is surprising as the declaration is right there. I haven't yet figured out how i want to fix this.

        Show
        Nathan Bubna added a comment - The trouble seems to be with abstract public methods declared in abstract classes and implemented in non-public classes. An enum class with an abstract public method shows this, but it also happens with things like: public abstract Foo { public abstract String getBar(); } Foo foo = new Foo() { public String getBar() { return "bar"; } }; I think this worked in Velocity 1.4 because the ClassMap implementation was based off of Class.getMethods, whereas it was changed to Class.getDeclaredMethods in 1.5 to speed things up. Calling getDeclaredMethods on Foo doesn't return getBar, which is surprising as the declaration is right there. I haven't yet figured out how i want to fix this.
        Hide
        Nathan Bubna added a comment -

        scratch that. ClassMap explicitly skipping abstract methods, ostensibly because their implementations would be found, forgetting that the implementing class might not be public. easy fix.

        Show
        Nathan Bubna added a comment - scratch that. ClassMap explicitly skipping abstract methods, ostensibly because their implementations would be found, forgetting that the implementing class might not be public. easy fix.
        Hide
        Nathan Bubna added a comment -

        Fixed in all revisions.

        Show
        Nathan Bubna added a comment - Fixed in all revisions.
        Hide
        Nathan Bubna added a comment -

        Er... i meant "versions".

        Show
        Nathan Bubna added a comment - Er... i meant "versions".

          People

          • Assignee:
            Unassigned
            Reporter:
            chad davis
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development