Velocity scripts fail to run after upgrading to Confluence 8 or later
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Velocity scripts (.vm
) cannot be executed succesfully after upgrading to Confluence 8 or later
Environment
Confluence 8 or later
Diagnosis
Apart from the fact that the script fails, in the atlassian-confluence.log
you could find the following error message:
2023-11-21 08:52:50,361 WARN [http-nio-8090-exec-10 url: /confluence/login.action] [confluence.impl.hibernate.ConfluenceHibernateTransactionManager] doRollback Performing rollback. Transactions:\n ->[null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT (Session #1227624352)
-- url: /confluence/login.action | userName: anonymous | referer: https://CONFLUENCE_URL/confluence/ | traceId: 9d59d9013c4856bb
2023-11-21 08:52:50,362 ERROR [http-nio-8090-exec-10 url: /confluence/login.action] [apache.struts2.dispatcher.DefaultDispatcherErrorHandler] sendErrorResponse Exception occurred during processing request: Encountered \"#end\\n\" at /login.vm[line 119, column 25]\nWas expecting one of:\n <EOF> \n \"(\" ...\n <RPAREN> ...\n <ESCAPE_DIRECTIVE> ...\n <SET_DIRECTIVE> ...\n \"##\" ...\n \"\\\\\\\\\" ...\n \"\\\\\" ...\n <TEXT> ...\n \"*#\" ...\n \"*#\" ...\n <STRING_LITERAL> ...\n <IF_DIRECTIVE> ...\n <STOP_DIRECTIVE> ...\n <INTEGER_LITERAL> ...\n <FLOATING_POINT_LITERAL> ...\n <WORD> ...\n <BRACKETED_WORD> ...\n <IDENTIFIER> ...\n <DOT> ...\n \"{\" ...\n \"}\" ...\n
-- url: /confluence/login.action | userName: anonymous | referer: https://CONFLUENCE_URL/confluence/ | traceId: 9d59d9013c4856bb
org.apache.velocity.exception.ParseErrorException: Encountered "#end\n" at /login.vm[line 119, column 25]
Was expecting one of:
<EOF>
"(" ...
<RPAREN> ...
<ESCAPE_DIRECTIVE> ...
<SET_DIRECTIVE> ...
"##" ...
"\\\\" ...
"\\" ...
<TEXT> ...
"*#" ...
"*#" ...
<STRING_LITERAL> ...
<IF_DIRECTIVE> ...
<STOP_DIRECTIVE> ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<WORD> ...
<BRACKETED_WORD> ...
<IDENTIFIER> ...
<DOT> ...
"{" ...
"}" ...
at org.apache.velocity.Template.process(Template.java:141)
at com.atlassian.confluence.velocity.ConfigurableResourceManager.loadResource(ConfigurableResourceManager.java:350)
at com.atlassian.confluence.velocity.ConfigurableResourceManager.getResource(ConfigurableResourceManager.java:298)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1400)
at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:422)
at org.apache.struts2.result.VelocityResult.getTemplate(VelocityResult.java:219)
at com.atlassian.xwork.results.ProfiledVelocityResult.getTemplate(ProfiledVelocityResult.java:27)
at org.apache.struts2.result.VelocityResult.doExecute(VelocityResult.java:146)
at com.atlassian.xwork.results.ProfiledVelocityResult.doExecute(ProfiledVelocityResult.java:18)
at com.atlassian.confluence.setup.struts.EncodingVelocityResult.doExecute(EncodingVelocityResult.java:43)
at org.apache.struts2.result.StrutsResultSupport.execute(StrutsResultSupport.java:206)
...
...
Cause
Confluence 8.0 introduced many platform related changes which can cause app failures. The full list of changes can be found in Preparing for Confluence 8.0
In order to modernise our code base, reduce tech debt and secure against OGNL attacks, Confluence team decided to move to Struts2.
Solution
As part of this migration, the #tag
and #bodytag
tags need to be migrated to the recommended new tags as per the Struts2 Upgrade Guide.
In depth details are available under section Update from 30 Aug 2022, where it is explained how to migrate the #bodytag( "Component" <parameters>)
and #bodytag( "TextField" <parameters>)
. Thought it is not mentioned, a similar approach also applies for #bodytag ( "Password" <parameters>)
if you are using it.