Thanks for taking time to look into this.
I know the template and I have updated it to make it even simpler. The current 
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 = 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.getTableName());
        props.put("resource.loader.ds.resource.key_column", 
velocityProperties.getKeyColumnName());
        props.put("resource.loader.ds.resource.template_column", 
velocityProperties.getTemplateColumnName());
        props.put("resource.loader.ds.resource.timestamp_column", 
velocityProperties.getTimestampColumnName());
        final var dsLoader = 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.runtime.log.NullLogSystem");
        props.put(RuntimeConstants.RESOURCE_MANAGER_INSTANCE, 
velocityResourceManager);
        final var mailVelocityEngine = new VelocityEngine(props);
        mailVelocityEngine.init();

(velocityProperties is an object to hold string values. dataSource is a 
javax.sql.DataSource, velocityResourceManager is a subclass of 
org.apache.velocity.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]> 
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.mergeTemplate when using 2.4 or 2.4.1

***  CAUTION  ***  This message came from an EXTERNAL address 
([email protected]). DO NOT click on 
links or attachments unless you know the sender and the content is safe. New 
Jersey State Government Employees Should Forward Messages That May Be Cyber 
Security Risks To [email protected].

Since it happens during the parsing, it means that it only depends on the 
template itself, not to the values provided to it.

So if you are able to log the template location, you will know the problematic 
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 works 
> 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 
> global library macros o.a.v.parser - XXXXXXXXXXXXXXXXXXXXXXXXXXXX: 
> offset -1, count 79, length 4096
> java.lang.StringIndexOutOfBoundsException: offset -1, count 79, length 4096
>          at java.base/java.lang.String.checkBoundsOffCount(String.java:3304) 
> ~[?:?]
>          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_token(StandardParser.java:5611)
>  ~[velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.parser.StandardParser.jj_3R_EndingZeroWidthWhitespace_1591_5_49(StandardParser.java:5448)
>  ~[velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.parser.StandardParser.jj_3_3(StandardParser.java:5454)
>  ~[velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.parser.StandardParser.jj_2_3(StandardParser.java:3886)
>  ~[velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.parser.StandardParser.Statement(StandardParser.java:654)
>  ~[velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.parser.StandardParser.process(StandardParser.java:495)
>  ~[velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.parser.StandardParser.parse(StandardParser.java:184)
>  [velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.RuntimeInstance.parse(RuntimeInstance.java:1344) 
> [velocity-engine-core-2.4.jar:2.4]
>          at org.apache.velocity.Template.process(Template.java:145) 
> [velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:429)
>  [velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:346)
>  [velocity-engine-core-2.4.jar:2.4]
>          at 
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1694)
>  [velocity-engine-core-2.4.jar:2.4]
>          at 
> 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 
> Services | NJ Dept. of Agriculture
>
> CONFIDENTIALITY NOTICE: The information contained in this communication from 
> New Jersey Department of Agriculture is privileged and confidential and is 
> intended for the sole use of the persons or entities who are the addressees. 
> If you are not an intended recipient of this email, the dissemination, 
> distribution, copying or use of the information it contains is strictly 
> prohibited. If you have received this communication in error, please 
> immediately 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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to