Velocity
  1. Velocity
  2. VELOCITY-443

Velocity 1.4 does not support Iterable collections.

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 1.6
    • Component/s: None
    • Labels:
      None
    • Environment:
      Java 5

      Description

      In the new for loop in Java 5 e.g.

      for(Object obj: iterable)

      the collection iterated only needs to be of type Iterable

      However, In Velocity a foreach loop must be either a Collection or a Map but cannot be just an Iterable.

      Suggestion, support Iterable containers.

        Activity

        Hide
        Nathan Bubna added a comment -

        Yeah, Geir had the same feedback on the list. I changed it to watch for this and give a nice error message should it happen. See UberspectImpl:145-166 for the latest implementation.

        Show
        Nathan Bubna added a comment - Yeah, Geir had the same feedback on the list. I changed it to watch for this and give a nice error message should it happen. See UberspectImpl:145-166 for the latest implementation.
        Hide
        Henning Schmiedehausen added a comment -

        That implies that iterator() always returns an Iterator object which might lead to hard-to-find ClassCastExceptions. I'd appreciate a catch (ClassCastException ) with a meaningful error message. Apart from that: Nice.

        Show
        Henning Schmiedehausen added a comment - That implies that iterator() always returns an Iterator object which might lead to hard-to-find ClassCastExceptions. I'd appreciate a catch (ClassCastException ) with a meaningful error message. Apart from that: Nice.
        Hide
        Nathan Bubna added a comment -

        Fixed in revision 579331.

        Show
        Nathan Bubna added a comment - Fixed in revision 579331.
        Hide
        Nathan Bubna added a comment -

        I see no reason not to simply support any object with an iterator() method. Then we get Iterable support and more, without dependency on JDK 5 or requiring the user to use a different Uberspect. It would also be completely backwards compatible and not affect performance of any previously functional templates.

        Show
        Nathan Bubna added a comment - I see no reason not to simply support any object with an iterator() method. Then we get Iterable support and more, without dependency on JDK 5 or requiring the user to use a different Uberspect. It would also be completely backwards compatible and not affect performance of any previously functional templates.
        Hide
        Henning Schmiedehausen added a comment -

        Ah well, that is what a Hackathon is for.

        I've added an implementation of a JDK 5 Uberspect to the whiteboard for addition post Velocity 1.5

        If you desperately need it, get the current trunk from SVN and get the JDK15UberspectImpl (all ~20 lines of it) from the whiteboard/henning/jdk15 directory.

        Show
        Henning Schmiedehausen added a comment - Ah well, that is what a Hackathon is for. I've added an implementation of a JDK 5 Uberspect to the whiteboard for addition post Velocity 1.5 If you desperately need it, get the current trunk from SVN and get the JDK15UberspectImpl (all ~20 lines of it) from the whiteboard/henning/jdk15 directory.
        Hide
        Henning Schmiedehausen added a comment -

        Postponed to post-1.5.

        Show
        Henning Schmiedehausen added a comment - Postponed to post-1.5.
        Hide
        Henning Schmiedehausen added a comment -

        Velocity 1.x is currently not using any JDK5 features. This is not planned to be changed for 1.5 but I will look into this definitely after 1.5.

        Show
        Henning Schmiedehausen added a comment - Velocity 1.x is currently not using any JDK5 features. This is not planned to be changed for 1.5 but I will look into this definitely after 1.5.

          People

          • Assignee:
            Nathan Bubna
            Reporter:
            Peter Lawrey
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development