You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Samarth Gupta <sa...@gmail.com> on 2022/09/23 17:35:36 UTC

Velocity.init(p) throws NPE sometimes

Hey folks,

We have been using `velocity-engine-core-2.3` in our product and it works
fine most of the time.
Our application runs on multiple clusters and on one particular cluster we
sometimes randomly get NPE during execution of  *Velocity.init(p)*

I have looked at the application code and tried to reproduce the issue on
the test cluster, but unable to do so.

Same set of properties used for init works fine for 1 -2 days and suddenly
we get NPE in same code path.

Any suggestions?


Below is the stack trace for the same

```
java.lang.NullPointerException: null
        at
org.apache.velocity.util.ExtProperties.clearProperty(ExtProperties.java:937)
~[velocity-engine-core-2.3.jar:2.3]
        at
org.apache.velocity.util.ExtProperties.setProperty(ExtProperties.java:848)
~[velocity-engine-core-2.3.jar:2.3]
        at
org.apache.velocity.util.ExtProperties.combine(ExtProperties.java:919)
~[velocity-engine-core-2.3.jar:2.3]
        at
org.apache.velocity.runtime.RuntimeInstance.setConfiguration(RuntimeInstance.java:626)
~[velocity-engine-core-2.3.jar:2.3]
        at
org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:748)
~[velocity-engine-core-2.3.jar:2.3]
        at
org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:230)
~[velocity-engine-core-2.3.jar:2.3]
        at org.apache.velocity.app.Velocity.init(Velocity.java:102)
~[velocity-engine-core-2.3.jar:2.3]

```

here is sample usage on how we init the velocity engine

Properties p = new Properties();
p.setProperty("resource.loaders", "class");
p.setProperty(
    "resource.loader.class.class",
    "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
Velocity.init(p);