Alexander Rosenberg created VELOCITY-872:
--------------------------------------------

             Summary: Parse error from arithmetic expression as an argument to 
a method
                 Key: VELOCITY-872
                 URL: https://issues.apache.org/jira/browse/VELOCITY-872
             Project: Velocity
          Issue Type: Bug
         Environment: VTL in user macro in Atlassian Confluence 5.9.4
            Reporter: Alexander Rosenberg


The following results in a ParserErrorException:

## @noparams

#set ($list = ["a", "b", "c"])
#set ($last = $list.get($list.size() - 1))
<p>$last</p>

org.apache.velocity.exception.ParseErrorException: Encountered "-" at 
getRenderedContent[line 4, column 38]
Was expecting one of:
    "," ...
    ")" ...

        at 
org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1202)
        at 
org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1164)
        at 
org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:219)
        at 
com.atlassian.confluence.util.velocity.VelocityUtils.writeRenderedContent(VelocityUtils.java:148)
        at 
com.atlassian.confluence.util.velocity.VelocityUtils.getRenderedContent(VelocityUtils.java:130)
        at 
com.atlassian.confluence.util.velocity.VelocityUtils.getRenderedContent(VelocityUtils.java:117)
        at 
com.atlassian.confluence.util.velocity.VelocityUtils.getRenderedContent(VelocityUtils.java:113)
        at 
com.atlassian.confluence.macro.GenericVelocityMacro.execute(GenericVelocityMacro.java:101)
        at 
com.atlassian.confluence.content.render.xhtml.view.macro.ViewMacroMarshaller.executeMacro(ViewMacroMarshaller.java:229)
        at 
com.atlassian.confluence.content.render.xhtml.view.macro.ViewMacroMarshaller.marshalInternal(ViewMacroMarshaller.java:156)
        at 
com.atlassian.confluence.content.render.xhtml.view.macro.ViewMacroMarshaller.lambda$marshal$445(ViewMacroMarshaller.java:113)
        at 
com.atlassian.confluence.impl.content.render.xhtml.analytics.MetricsCollectingMarshaller.marshal(MetricsCollectingMarshaller.java:49)
~~~snipped~~~

The Velocity parser does not appear to support arithmetic expressions as 
arguments in method calls.  I find this extremely surprising, given the 
ubiquity of this basic syntax among most languages.

## This works as expected:
#set ($lastIndex = $list.size() - 1)
#set ($last = $list.get($lastIndex))
<p>$last</p>




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org
For additional commands, e-mail: dev-h...@velocity.apache.org

Reply via email to