Inconsistent and strange NPE when initializing Velocity
Bradley Wagner <[email protected]>
| Newsgroups | gmane.comp.jakarta.velocity.user |
|---|---|
| Message-ID | <CAEbivYUZjZxnOoqbVY2nmBiNEA2eGyr-WK_eiOPGct-fHo=iZg@mail.gmail.com> |
Hi,
I sent this message before I had subscribed to the list so I wasn't sure if
the original made it. My apologies if this is a duplicate.
One of our clients running our software is *occasionally* running into the
stack trace at the bottom when Velocity is initialized. A restart tends to
fix this problem. But it pops back up after running the system for a while.
They're running:
- Velocity 1.7
- Tomcat 6.0.35
- Using the 3.2 of the Apache Commons Collections library
- Running Java 1.6.0_31 in Mac OS X 10.6.8
Unfortunately we don't have the ability to debug this problem remotely, so
we can't see exactly what's going on, but having looked a bit at the
Extended Properties class, it doesn't seem like it should be possible to
get an NPE at that line, because of the containsKey() check a few lines
before.
java.lang.NullPointerException
at org.apache.commons.collections.ExtendedProperties.clearProperty(ExtendedProperties.java:797)
at org.apache.commons.collections.ExtendedProperties.setProperty(ExtendedProperties.java:722)
at org.apache.commons.collections.ExtendedProperties.combine(ExtendedProperties.java:783)
at org.apache.velocity.runtime.RuntimeInstance.setProperties(RuntimeInstance.java:657)
at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:645)
at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:226)
at org.apache.velocity.app.Velocity.init(Velocity.java:97)
at com.hannonhill.cascade.velocity.VelocityEngineUtil.generateMessage(VelocityEngineUtil.java:66)
Also, here's the code that's calling the Velocity.init:
Properties velocityProps = VelocityProperties.getProperties();
Velocity.init(velocityProps);
Velocity Properties are just loading the following file contents into a
properties object:
#----------------------------------------------------------------------------
# This controls if Runtime.error(), info() and warn() messages include the
# whole stack trace. The last property controls whether invalid references
# are logged.
#----------------------------------------------------------------------------
runtime.log.error.stacktrace = false
runtime.log.warn.stacktrace = false
runtime.log.info.stacktrace = false
runtime.log.invalid.reference = true
#----------------------------------------------------------------------------
# Configuration for the Log4JLogSystem.
# You must define the runtime.log.logsystem.class property to be:
# org.apache.velocity.runtime.log.Log4JLogSystem
#
# You must also include Log4J's .jar files into your classpath. They are
# included with the Velocity distribution in the build/lib directory.
#
# There are several different options that you can configure.
# Uncomment the ones that you want and also define their settings.
#----------------------------------------------------------------------------
#----------------------------------------------------------------------------
# T E M P L A T E E N C O D I N G
#----------------------------------------------------------------------------
input.encoding=UTF-8
output.encoding=UTF-8
#----------------------------------------------------------------------------
# F O R E A C H P R O P E R T I E S
#----------------------------------------------------------------------------
# These properties control how the counter is accessed in the #foreach
# directive. By default the reference $velocityCount will be available
# in the body of the #foreach directive. The default starting value
# for this reference is 1.
#----------------------------------------------------------------------------
directive.foreach.counter.name = velocityCount
directive.foreach.counter.initial.value = 1
#----------------------------------------------------------------------------
# T E M P L A T E L O A D E R S
#----------------------------------------------------------------------------
resource.loader = class
class.resource.loader.description = Velocity Classpath Resource Loader
class.resource.loader.class =
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader