[jira] [Closed] (VELOCITY-988) Regression Bug in Velocity Library: JSON if Condition with {} Failing in v2.3 and Later
"Claude Brisson (Jira)" <[email protected]> Sun, 14 Jun 2026 16:53:00 +0000 (UTC)
| Newsgroups | gmane.comp.jakarta.velocity.devel |
|---|---|
| Message-ID | <[email protected]> |
[ https://issues.apache.org/jira/browse/VELOCITY-988?page=3Dcom.atlass=
ian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claude Brisson closed VELOCITY-988.
-----------------------------------
> Regression Bug in Velocity Library: JSON if Condition with {} Failing in =
v2.3 and Later
> -------------------------------------------------------------------------=
--------------
>
> Key: VELOCITY-988
> URL: https://issues.apache.org/jira/browse/VELOCITY-988
> Project: Velocity
> Issue Type: Bug
> Components: Engine
> Affects Versions: 2.3, 2.4, 2.4.1
> Reporter: Muskaan12
> Assignee: Claude Brisson
> Priority: Major
> Fix For: 2.5
>
>
> I have identified a regression bug in the Velocity library that affects t=
he handling of=C2=A0{{if}}=C2=A0conditions within JSON documents when curly=
braces ({{{{}}{}{{}}}}) are present. This issue is identified in version 2=
.3 and present in later=C2=A0 versions as well, but was working as expected=
in=C2=A0 version 1.7.
> To help reproduce the issue, I have provided a sample code along with the=
stack trace in the following=C2=A0
> =C2=A0
> {code:java}
> public static void main(String[] args) {
> // Initialize the VelocityEngine
> VelocityEngine velocityEngine =3D new VelocityEngine();
> velocityEngine.init();
> // Define the template with a basic and simple if condition
> String template =3D "{\n" +
> " #if($!{$SubjectData.StudyEventData['@StudyEventRepeatKey']})\n" +
> " \"eventRepeatKey\": \"$SubjectData.StudyEventData['@StudyEventRepeatKey=
']\",\n" +
> " #end\n" +
> " \"otherField\": \"someValue\"\n" +
> "}";
> // Create VelocityContext and add data
> VelocityContext context =3D new VelocityContext();
> context.put("SubjectData", Map.of("StudyEventData", Map.of("@StudyEventRe=
peatKey", "123")));
> // Render the template
> StringWriter writer =3D new StringWriter();
> velocityEngine.evaluate(context, writer, "Template", template);
> // Print the rendered JSON
> System.out.println(writer.toString());
> }{code}
> =C2=A0
> *Stacktrace:*
> *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*
> *Exception in thread "main" org.apache.velocity.excep*
> *Exception in thread "main" org.apache.velocity.exception.ParseErrorExcep=
tion: Encountered ")\n" at Template[line 2, column 64]*
> *Was expecting one of:*
> =C2=A0 =C2=A0 *"||" ...*
> =C2=A0 =C2=A0 *")" ...*
> =C2=A0 =C2=A0 *<WHITESPACE> ...*
> =C2=A0 =C2=A0 *<NEWLINE> ...*
> =C2=A0 =C2=A0 *"-" ...*
> =C2=A0 =C2=A0 *"+" ...*
> =C2=A0 =C2=A0 {*}"{*}" ...*
> =C2=A0 =C2=A0 *"/" ...*
> =C2=A0 =C2=A0 *"%" ...*
> =C2=A0 =C2=A0 *<LOGICAL_AND> ...*
> =C2=A0 =C2=A0 *<LOGICAL_OR> ...*
> =C2=A0 =C2=A0 *<LOGICAL_LT> ...*
> =C2=A0 =C2=A0 *<LOGICAL_LE> ...*
> =C2=A0 =C2=A0 *<LOGICAL_GT> ...*
> =C2=A0 =C2=A0 *<LOGICAL_GE> ...*
> =C2=A0 =C2=A0 *<LOGICAL_EQUALS> ...*
> =C2=A0 =C2=A0 *<LOGICAL_NOT_EQUALS> ...*
> =C2=A0 =C2=A0**=C2=A0 =C2=A0
> *at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.=
java:1440)*
> *at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.=
java:1398)*
> *at org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:2=
13)*
> *at org.example.VelocityExample.main(VelocityExample.java:28)*
> *tion.ParseErrorException: Encountered ")\n" at Template[line 2, column 6=
4]*
> *Was expecting one of:*
> =C2=A0 =C2=A0 *"||" ...*
> =C2=A0 =C2=A0 *")" ...*
> =C2=A0 =C2=A0 *<WHITESPACE> ...*
> =C2=A0 =C2=A0 *<NEWLINE> ...*
> =C2=A0 =C2=A0 *"-" ...*
> =C2=A0 =C2=A0 *"+" ...*
> =C2=A0 =C2=A0 {*}"{*}" ...*
> =C2=A0 =C2=A0 *"/" ...*
> =C2=A0 =C2=A0 *"%" ...*
> =C2=A0 =C2=A0 *<LOGICAL_AND> ...*
> =C2=A0 =C2=A0 *<LOGICAL_OR> ...*
> =C2=A0 =C2=A0 *<LOGICAL_LT> ...*
> =C2=A0 =C2=A0 *<LOGICAL_LE> ...*
> =C2=A0 =C2=A0 *<LOGICAL_GT> ...*
> =C2=A0 =C2=A0 *<LOGICAL_GE> ...*
> =C2=A0 =C2=A0 *<LOGICAL_EQUALS> ...*
> =C2=A0 =C2=A0 *<LOGICAL_NOT_EQUALS> ...*
> =C2=A0 =C2=A0**=C2=A0 =C2=A0
> *at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.=
java:1440)*
> *at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.=
java:1398)*
> *at org.apache.velocity.app.VelocityEngine.evaluate(VelocityEngine.java:2=
13)*
> *at org.example.VelocityExample.main(VelocityExample.java:28)*
--
This message was sent by Atlassian Jira
(v8.20.10#820010)