0

I have came across an issue while using Velocity template. It is throwing NullPointerException for Directive.postRender for a foreach function used in my template.

Strange behavior is that with exactly same template and same input data, Velocity is successfully able to complete the evaluation process. It fails say 1 in 100 times.

Can anyone share insights please? Thanks in advance!

Version : Velocity 1.7

java.lang.NullPointerException: null
    at org.apache.velocity.runtime.directive.Directive.postRender(Directive.java:202) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.directive.Foreach.clean(Foreach.java:489) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.directive.Foreach.render(Foreach.java:443) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.RuntimeInstance.render(RuntimeInstance.java:1378) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.runtime.RuntimeInstance.evaluate(RuntimeInstance.java:1314) ~[velocity-1.7.jar:1.7]
    at org.apache.velocity.app.Velocity.evaluate(Velocity.java:254) ~[velocity-1.7.jar:1.7]

www.hybriscx.com
  • 1,129
  • 4
  • 22
  • The best would be to be able to reproduce it on a simple example. Or at least to share with us the relevant template parts. That said, Velocity v1.7 is pretty old. Last version is 2.1. – Claude Brisson Nov 05 '19 at 14:44

1 Answers1

0

Managed to fix by changing code from using Velocity.init() to

VelocityEngine vc = new VelocityEngine();
vc.init();

1st one was a singleton implementation and Velocity might be loosing some data in heavily multi-threaded mode. By changing it to use new instance for each pdf generation call, it is working like a charm.

Thanks!

www.hybriscx.com
  • 1,129
  • 4
  • 22