简体   繁体   English

Velocity 1.7 - 有时 Directive.postRender 在 Velocity.evaluate 中抛出 NullPointerException

[英]Velocity 1.7 - Sometimes Directive.postRender throws NullPointerException in Velocity.evaluate

I have came across an issue while using Velocity template.我在使用 Velocity 模板时遇到了一个问题。 It is throwing NullPointerException for Directive.postRender for a foreach function used in my template.它正在为我的模板中使用的 foreach function 引发Directive.postRenderNullPointerException

Strange behavior is that with exactly same template and same input data, Velocity is successfully able to complete the evaluation process.奇怪的行为是,使用完全相同的模板和相同的输入数据,Velocity 能够成功地完成评估过程。 It fails say 1 in 100 times.它失败说100次。

Can anyone share insights please?有人可以分享见解吗? Thanks in advance!提前致谢!

Version : Velocity 1.7版本:速度 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]

Managed to fix by changing code from using Velocity.init() to通过将代码从使用Velocity.init()更改为

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

1st one was a singleton implementation and Velocity might be loosing some data in heavily multi-threaded mode.第一个是 singleton 实现,Velocity 可能会在大量多线程模式下丢失一些数据。 By changing it to use new instance for each pdf generation call, it is working like a charm.通过将其更改为对每个 pdf 代调用使用新实例,它就像一个魅力。

Thanks!谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM