RE: [EXTERNAL] Re: Unexpected exception calling VelocityEngine.mergeTemplate when using 2.4 or 2.4.1
"Kish, Robert [AG]" <[email protected]> Thu, 12 Jun 2025 13:52:01 +0000
| Newsgroups | gmane.comp.jakarta.velocity.user |
|---|---|
| Message-ID | <PH8PR09MB9628609DF0717F21F7E1886FAD74A@PH8PR09MB9628.namprd09.prod.outlook.com> |
Thanks for taking time to look into this.
I know the template and I have updated it to make it even simpler. The curr=
ent template is currently set to the text "Hi", without quotes.
p-nio-8080-exec-3] o.a.v.parser - FDMS Self-Reg Invite Subject: offset -1, =
count 5, length 4096
java.lang.StringIndexOutOfBoundsException: offset -1, count 5, length 4096
The initialization code is the following:
final var props =3D new Properties();
props.put("resource.loaders", "ds");
props.put("resource.loader.ds.class", "org.apache.velocity.runtime.=
resource.loader.DataSourceResourceLoader");
props.put("resource.loader.ds.resource.table", velocityProperties.g=
etTableName());
props.put("resource.loader.ds.resource.key_column", velocityPropert=
ies.getKeyColumnName());
props.put("resource.loader.ds.resource.template_column", velocityPr=
operties.getTemplateColumnName());
props.put("resource.loader.ds.resource.timestamp_column", velocityP=
roperties.getTimestampColumnName());
final var dsLoader =3D new DataSourceResourceLoader();
dsLoader.setDataSource(dataSource);
props.put("resource.loader.ds.instance", dsLoader);
props.put("resource.loader.ds.cache", "true");
props.put("runtime.log.logsystem.class", "org.apache.velocity.runti=
me.log.NullLogSystem");
props.put(RuntimeConstants.RESOURCE_MANAGER_INSTANCE, velocityResou=
rceManager);
final var mailVelocityEngine =3D new VelocityEngine(props);
mailVelocityEngine.init();
(velocityProperties is an object to hold string values. dataSource is a jav=
ax.sql.DataSource, velocityResourceManager is a subclass of org.apache.velo=
city.runtime.resource.ResourceManagerImpl)
If there's anything else you think I should try or can provide you, please =
let me know. Thanks!
-----Original Message-----
From: Claude Brisson <[email protected]>=20
Sent: Thursday, June 12, 2025 02:27 AM
To: Kish, Robert [AG] <[email protected]>; Velocity Users List =
<[email protected]>
Subject: [EXTERNAL] Re: Unexpected exception calling VelocityEngine.mergeTe=
mplate when using 2.4 or 2.4.1
*** CAUTION *** This message came from an EXTERNAL address (user-return-=
[email protected]). DO NOT click on links o=
r attachments unless you know the sender and the content is safe. New Jerse=
y State Government Employees Should Forward Messages That May Be Cyber Secu=
rity Risks To [email protected].
Since it happens during the parsing, it means that it only depends on the t=
emplate itself, not to the values provided to it.
So if you are able to log the template location, you will know the problema=
tic template at least.
I'm going to try to pinpoint the problem with the stack trace you provided =
and let you know if I am able to identify the cause.
On 10/06/2025 23:50, Kish, Robert [AG] wrote:
> Hello!
>
> We have 2 similar environments and under Velocity Engine 2.3, the code wo=
rks as expected and we get back the template from the API call.
> But when upgrading to 2.4.1 (or trying 2.4) one of our environments fails=
with an exception. Unfortunately, it's in an environment where I can't use=
a debugger.
>
> I'm looking for ideas on how to resolve this issue or identify a specific=
bug that can be reported to the Velocity Team for resolution.
>
> Log + Exception
> o.a.v.macro - autoload off: VM system will not automatically reload=20
> global library macros o.a.v.parser - XXXXXXXXXXXXXXXXXXXXXXXXXXXX:=20
> offset -1, count 79, length 4096
> java.lang.StringIndexOutOfBoundsException: offset -1, count 79, length 40=
96
> at java.base/java.lang.String.checkBoundsOffCount(String.java:33=
04) ~[?:?]
> at java.base/java.lang.String.rangeCheck(String.java:280) ~[?:?]
> at java.base/java.lang.String.<init>(String.java:276) ~[?:?]
> at org.apache.velocity.runtime.parser.VelocityCharStream.=
GetImage(VelocityCharStream.java:434) ~[velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.parser.StandardParserTokenManager=
.jjFillToken(StandardParserTokenManager.java:7796) ~[velocity-engine-core-2=
.4.jar:2.4]
> at org.apache.velocity.runtime.parser.StandardParserTokenManager=
.getNextToken(StandardParserTokenManager.java:7866) ~[velocity-engine-core-=
2.4.jar:2.4]
> at org.apache.velocity.runtime.parser.StandardParser.jj_scan_tok=
en(StandardParser.java:5611) ~[velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.parser.StandardParser.jj_3R_Endin=
gZeroWidthWhitespace_1591_5_49(StandardParser.java:5448) ~[velocity-engine-=
core-2.4.jar:2.4]
> at org.apache.velocity.runtime.parser.StandardParser.jj_3_3(Stan=
dardParser.java:5454) ~[velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.parser.StandardParser.jj_2_3(Stan=
dardParser.java:3886) ~[velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.parser.StandardParser.Statement(S=
tandardParser.java:654) ~[velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.parser.StandardParser.process(Sta=
ndardParser.java:495) ~[velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.parser.StandardParser.parse(Stand=
ardParser.java:184) [velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.RuntimeInstance.parse(RuntimeInst=
ance.java:1344) [velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.Template.process(Template.java:145) [velo=
city-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.resource.ResourceManagerImpl.load=
Resource(ResourceManagerImpl.java:429) [velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.resource.ResourceManagerImpl.getR=
esource(ResourceManagerImpl.java:346) [velocity-engine-core-2.4.jar:2.4]
> at org.apache.velocity.runtime.RuntimeInstance.getTemplate(Runti=
meInstance.java:1694) [velocity-engine-core-2.4.jar:2.4]
> at=20
> org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.ja
> va:284) [velocity-engine-core-2.4.jar:2.4]
>
> Environment that throws the exception:
> Linux / Tomcat
>
> Server version name: Apache Tomcat/9.0.104
> Server built: Apr 4 2025 12:32:55 UTC
> Server version number: 9.0.104.0
> OS Name: Linux
> OS Version: 4.14.355-277.647.amzn2.x86_64
> Architecture: amd64
> Java Home: /usr/lib/jvm/java-11-amazon-corretto.x86_64
> JVM Version: 11.0.27+6-LTS
> JVM Vendor: Amazon.com Inc.
>
>
> Environment that does not throw the exception:
> Windows / TomEE
>
> INFO: Server version name: Apache Tomcat (TomEE)/9.0.82 (8.0.16)
> INFO: Server built: Oct 11 2023 13:15:08 UTC
> INFO: Server version number: 9.0.82.0
> INFO: OS Name: Windows 11
> INFO: OS Version: 10.0
> INFO: Architecture: amd64
> INFO: Java Home: C:\Program Files\Amazon Corretto\jdk11.0.26_=
4
> INFO: JVM Version: 11.0.26+4-LTS
> INFO: JVM Vendor: Amazon.com Inc.
>
> Robert Kish (Consultant) | Application Developer, IT Application=20
> Services | NJ Dept. of Agriculture
>
> CONFIDENTIALITY NOTICE: The information contained in this communication f=
rom New Jersey Department of Agriculture is privileged and confidential and=
is intended for the sole use of the persons or entities who are the addres=
sees. If you are not an intended recipient of this email, the dissemination=
, distribution, copying or use of the information it contains is strictly p=
rohibited. If you have received this communication in error, please immedia=
tely contact the sender of this email message to arrange for the return of =
this information.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]