[
https://issues.apache.org/jira/browse/VELOCITY-872?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Alexander Rosenberg updated VELOCITY-872:
-----------------------------------------
Description:
The following results in a {{ParserErrorException}}:
{noformat}
## @noparams
#set ($list = ["a", "b", "c"])
#set ($last = $list.get($list.size() - 1))
<p>$last</p>
{noformat}
The message that appears in atlassian-confluence.log:
{noformat}
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~~~
{noformat}
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 languages. I hope that this is just a
result of Confluence using an older version of Velocity.
This is a workaround:
{noformat}
## This works as expected:
#set ($lastIndex = $list.size() - 1)
#set ($last = $list.get($lastIndex))
<p>$last</p>
{noformat}
was:
The following results in a {{ParserErrorException}}:
{noformat}
## @noparams
#set ($list = ["a", "b", "c"])
#set ($last = $list.get($list.size() - 1))
<p>$last</p>
{noformat}
{noformat}
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~~~
{noformat}
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.
{noformat}
## This works as expected:
#set ($lastIndex = $list.size() - 1)
#set ($last = $list.get($lastIndex))
<p>$last</p>
{noformat}
> 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}}:
> {noformat}
> ## @noparams
> #set ($list = ["a", "b", "c"])
> #set ($last = $list.get($list.size() - 1))
> <p>$last</p>
> {noformat}
> The message that appears in atlassian-confluence.log:
> {noformat}
> 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~~~
> {noformat}
> 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 languages. I hope that this is just a
> result of Confluence using an older version of Velocity.
> This is a workaround:
> {noformat}
> ## This works as expected:
> #set ($lastIndex = $list.size() - 1)
> #set ($last = $list.get($lastIndex))
> <p>$last</p>
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]