Velocity
  1. Velocity
  2. VELOCITY-528

Velocity 1.5 raises errors for templates that ran in 1.4.

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.6
    • Component/s: Documentation
    • Labels:
      None
    • Environment:
      Windows XP SP2, JDK 1.5

      Description

      Migrated from Velocity 1.4 to 1.5. I have several templates that ran in 1.4 and now fail in 1.5. I raised this in the mailing list and Nathan Bubna asked me to file a bug.

      This is probably an error in my template, but 1.4 allowed it to execute without complaints. I might have been lucky that nothing bad happened.

      Existing templates contain the following.

      public $method.returnType $method.name(
      #foreach($param in $parameters)
      ...
      #end

      The intent here is to emit a java method signature for a method named $method.name . This works in 1.4.

      In Velocity 1.5, an error is thrown indicating that the #foreach is unexpected. Velocity 1.5 is expecting a method parameter becuase the variable name is terminated by an open paren.

      I fixed the problem by adding curly braces to the template as follows:
      public $method.returnType $

      {method.name}

      (
      #foreach($param in $parameters)
      ...
      #end

      This is probably a bug in 1.4, and poor coding practice in my template, but given the fact that it did work and now doesn't, there should be some mention of this "improvement" in the 1.5 release notes.

        Activity

        Hide
        Nathan Bubna added a comment -

        Regression documented in 1.6, this was just open as a 1.5.1 CANDIDATE

        Show
        Nathan Bubna added a comment - Regression documented in 1.6, this was just open as a 1.5.1 CANDIDATE
        Hide
        Nathan Bubna added a comment -

        Only relevant to theoretical, but unlikely 1.5.x releases.

        Show
        Nathan Bubna added a comment - Only relevant to theoretical, but unlikely 1.5.x releases.
        Hide
        Nathan Bubna added a comment -

        Documentation of this regression has been added to the http://wiki.apache.org/velocity/Velocity15ReleaseNotes

        It should also be added to any/all 1.5.x release notes before marking this issue resolved.

        Show
        Nathan Bubna added a comment - Documentation of this regression has been added to the http://wiki.apache.org/velocity/Velocity15ReleaseNotes It should also be added to any/all 1.5.x release notes before marking this issue resolved.
        Hide
        Ben Speakmon added a comment -

        Thanks for the explanation, Nathan.

        Show
        Ben Speakmon added a comment - Thanks for the explanation, Nathan.
        Hide
        Nathan Bubna added a comment -

        This bug was raised as a result of this discussion:
        http://mail-archives.apache.org/mod_mbox/velocity-user/200703.mbox/%3c4d651da50703121333n80e8419nf7611dc789e39a83@mail.gmail.com%3e

        Essentially, the parser was previously gracious to Michael's templates where it probably should not have been (though that could be debated). Now that new lines are allowed in method calls, e.g.:

        $tool.method( $foo,
        'bar',
        "$woogie" )

        Michael's templates are breaking in places where he did things like the above, but did not mean for such a method to be called, rather he only meant to have $tool.method resolve into the name of a java method.

        The workaround for this is to update the templates to use formal reference notation as so:

        $

        {tool.method}

        ( $foo,
        'bar',
        "$woogie" )

        This was an unintended break in backwards compatibility, due to the fact that what Michael was doing previously was never really intended. Regardless, this needs to be added to the release notes, so it does not surprise other users. It would also be prudent to make a point in the documentation to recommend users always use formal reference notation whenever their reference is followed by ANY character other than whitespace. This makes things clear to both the parser and anyone else looking at their template, and thus should be considered a best practice.

        Show
        Nathan Bubna added a comment - This bug was raised as a result of this discussion: http://mail-archives.apache.org/mod_mbox/velocity-user/200703.mbox/%3c4d651da50703121333n80e8419nf7611dc789e39a83@mail.gmail.com%3e Essentially, the parser was previously gracious to Michael's templates where it probably should not have been (though that could be debated). Now that new lines are allowed in method calls, e.g.: $tool.method( $foo, 'bar', "$woogie" ) Michael's templates are breaking in places where he did things like the above, but did not mean for such a method to be called, rather he only meant to have $tool.method resolve into the name of a java method. The workaround for this is to update the templates to use formal reference notation as so: $ {tool.method} ( $foo, 'bar', "$woogie" ) This was an unintended break in backwards compatibility, due to the fact that what Michael was doing previously was never really intended. Regardless, this needs to be added to the release notes, so it does not surprise other users. It would also be prudent to make a point in the documentation to recommend users always use formal reference notation whenever their reference is followed by ANY character other than whitespace. This makes things clear to both the parser and anyone else looking at their template, and thus should be considered a best practice.
        Hide
        Ben Speakmon added a comment -

        Michael,

        Did you find out what was going on here? Was it something you were doing wrong, or do you think it's something in velocity?

        Show
        Ben Speakmon added a comment - Michael, Did you find out what was going on here? Was it something you were doing wrong, or do you think it's something in velocity?

          People

          • Assignee:
            Unassigned
            Reporter:
            Michael Giroux
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development