You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "B. Scott Smith" <sc...@smithdomain.com> on 2010/07/01 18:33:08 UTC

NullPointerException in init() during redeploy

Hi,

I have finally finished moving my application from Velocity 1.4/Tools 
1.4 to Velocity 1.6.4/Tools 2.0 (thanks for your help Nathan).
Unfortunately, I am hitting a serious snag during the re-deploy. My 
Servlet is extending VelocityViewServlet, and the NullPointerException 
is being thrown in my init() method, when calling super.init(). The 
problem is occurring in 
org.apache.velocity.runtime.RuntimeInstance#setDefaultProperties():

     inputStream = getClass()
         .getResourceAsStream('/' + DEFAULT_RUNTIME_PROPERTIES);

The input stream it is returning is NULL. This only seems to happen when 
I re-deploy into my Servlet Container (I am using Jetty). If I then shut 
down the entire JVM and restart, the application runs fine. 
Unfortunately, restarting the JVM to deploy my app everywhere is not an 
option. If I catch and ignore the Exception, the rest of my application 
runs fine (but any access to the Velocity Engine generates errors).

Here is the stack trace I am receiving. Any help or guidance would be 
greatly appreciated.

  java.lang.NullPointerException
        at java.io.Reader.<init>(Unknown Source)
        at java.io.InputStreamReader.<init>(Unknown Source)
        at 
org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:543)
        at 
org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:519)
        at 
org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:397)
        at 
org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:570)
        at 
org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:249)
        at 
org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:107)
        at 
org.apache.velocity.tools.view.VelocityView.init(VelocityView.java:347)
        at 
org.apache.velocity.tools.view.VelocityView.init(VelocityView.java:310)
        at 
org.apache.velocity.tools.view.VelocityView.<init>(VelocityView.java:213)
        at 
org.apache.velocity.tools.view.ServletUtils.createView(ServletUtils.java:156)
        at 
org.apache.velocity.tools.view.ServletUtils.getVelocityView(ServletUtils.java:142)
        at 
org.apache.velocity.tools.view.ServletUtils.getVelocityView(ServletUtils.java:104)
        at 
org.apache.velocity.tools.view.VelocityViewServlet.getVelocityView(VelocityViewServlet.java:155)
        at 
org.apache.velocity.tools.view.VelocityViewServlet.init(VelocityViewServlet.java:122)
        at rss.starter.MyTestServlet.init(MyTestServlet.java:147)
        at 
org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
        at 
org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
        at 
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
        at 
org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
        at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
        at 
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
        at 
org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
        at 
org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
        at 
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
        at 
org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
        at org.mortbay.jetty.Server.doStart(Server.java:224)
        at 
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
        at rss.jettywrapper.JettyWrapper.startServer(JettyWrapper.java:142)
        at rss.jettywrapper.JettyWrapper.upgradeCheck(JettyWrapper.java:204)
        at rss.jettywrapper.JettyWrapper.access$100(JettyWrapper.java:24)
        at rss.jettywrapper.JettyWrapper$1.run(JettyWrapper.java:80)
        at java.lang.Thread.run(Unknown Source)
  java.lang.RuntimeException: Could not initialize VelocityEngine: 
java.lang.NullPointerException
        at 
org.apache.velocity.tools.view.VelocityView.init(VelocityView.java:354)
        at 
org.apache.velocity.tools.view.VelocityView.init(VelocityView.java:310)
        at 
org.apache.velocity.tools.view.VelocityView.<init>(VelocityView.java:213)
<same stack as above>
  Caused by: java.lang.NullPointerException
        at java.io.Reader.<init>(Unknown Source)
        at java.io.InputStreamReader.<init>(Unknown Source)
        at 
org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:543)
        at 
org.apache.commons.collections.ExtendedProperties.load(ExtendedProperties.java:519)
        at 
org.apache.velocity.runtime.RuntimeInstance.setDefaultProperties(RuntimeInstance.java:397)
        at 
org.apache.velocity.runtime.RuntimeInstance.initializeProperties(RuntimeInstance.java:570)
        at 
org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:249)
        at 
org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:107)
        at 
org.apache.velocity.tools.view.VelocityView.init(VelocityView.java:347)
        ... 25 more

Thank you.
  - Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: NullPointerException in init() during redeploy

Posted by Nathan Bubna <nb...@gmail.com>.
Yeah, that certainly sounds like a Jetty classloader/resourcestream
issue.  have you tried contacting the Jetty people?  I really don't
know what could be done to compensate besides the modifications you
made early to hardcode properties.

On Mon, Jul 5, 2010 at 6:36 PM, B. Scott Smith <sc...@smithdomain.com> wrote:
> OK, I tried deploying my original application in JBoss 3.x with embedded
> Jetty. When I attempted to deploy my upgraded app, I received the same
> Velocity errors. I then tried deploying in JBoss 5.1 with embedded Tomcat.
> When I deployed the upgraded app, I received no errors, and it performed as
> expected.
> So, this would imply that this is an issue with Jetty? Is there something I
> might be able to do in my app to compensate?
>  - Scott
>
> On 7/1/2010 3:40 PM, B. Scott Smith wrote:
>>
>> I am using Jetty 6.1.24 (latest stable release). I tried a much older
>> version (Jetty 4.2.x) and the problem also occurs.
>> I am running JREv1.6, but it also fails on JREv1.4.2.
>> I will try to setup an environment to deploy it in Tomcat and see, but it
>> may take a while.
>>
>> In doing more tests, I have discovered some additional things.
>> First, I added a line in
>> org.apache.velocity.runtime.RuntimeInstance#setDefaultProperties():
>>
>> log.error("getResourceAsStream() returned null:
>> "+getClass().getResource('/'+DEFAULT_RUNTIME_PROPERTIES));
>>
>> and this shows a valid URL, so it is able to find the resource, but won't
>> provide an inputStream to it. It prints:
>>
>> getResourceAsStream() returned null:
>>  jar:file:<path to my
>> app>/WEB-INF/lib/velocity-dep.jar!/org/apache/velocity/runtime/defaults/velocity.properties
>>
>> Second, if I copy all of the default properties into my own
>> velocity.properties file, and return with no error from
>> setDefaultProperties(), it then blows up in initializeDirectives() with the
>> same problem (inputStream is null). If I modify it to hardcode the 8
>> properties from the directives.properties file and return, then my
>> application runs fine. So, the ONLY issue is trying to load these properties
>> files from the velocity-dep.jar, no other issues occur.
>> Somehow, my ClassLoader is getting messed up, and I can't figure out how
>> to "reset" it.
>>  - Scott
>>
>> On 7/1/2010 2:07 PM, Antonio Petrelli wrote:
>>>
>>> 2010/7/1 B. Scott Smith<sc...@smithdomain.com>:
>>>>
>>>> The input stream it is returning is NULL. This only seems to happen when
>>>> I
>>>> re-deploy into my Servlet Container (I am using Jetty). If I then shut
>>>> down
>>>> the entire JVM and restart, the application runs fine.
>>>
>>> What version of Jetty are you using? If you deploy it in, say, Tomcat,
>>> does it work?
>>>
>>> Antonio
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: NullPointerException in init() during redeploy

Posted by "B. Scott Smith" <sc...@smithdomain.com>.
OK, I tried deploying my original application in JBoss 3.x with embedded 
Jetty. When I attempted to deploy my upgraded app, I received the same 
Velocity errors. I then tried deploying in JBoss 5.1 with embedded 
Tomcat. When I deployed the upgraded app, I received no errors, and it 
performed as expected.
So, this would imply that this is an issue with Jetty? Is there 
something I might be able to do in my app to compensate?
  - Scott

On 7/1/2010 3:40 PM, B. Scott Smith wrote:
> I am using Jetty 6.1.24 (latest stable release). I tried a much older 
> version (Jetty 4.2.x) and the problem also occurs.
> I am running JREv1.6, but it also fails on JREv1.4.2.
> I will try to setup an environment to deploy it in Tomcat and see, but 
> it may take a while.
>
> In doing more tests, I have discovered some additional things.
> First, I added a line in 
> org.apache.velocity.runtime.RuntimeInstance#setDefaultProperties():
>
> log.error("getResourceAsStream() returned null: 
> "+getClass().getResource('/'+DEFAULT_RUNTIME_PROPERTIES));
>
> and this shows a valid URL, so it is able to find the resource, but 
> won't provide an inputStream to it. It prints:
>
> getResourceAsStream() returned null:
>   jar:file:<path to my 
> app>/WEB-INF/lib/velocity-dep.jar!/org/apache/velocity/runtime/defaults/velocity.properties 
>
>
> Second, if I copy all of the default properties into my own 
> velocity.properties file, and return with no error from 
> setDefaultProperties(), it then blows up in initializeDirectives() 
> with the same problem (inputStream is null). If I modify it to 
> hardcode the 8 properties from the directives.properties file and 
> return, then my application runs fine. So, the ONLY issue is trying to 
> load these properties files from the velocity-dep.jar, no other issues 
> occur.
> Somehow, my ClassLoader is getting messed up, and I can't figure out 
> how to "reset" it.
>  - Scott
>
> On 7/1/2010 2:07 PM, Antonio Petrelli wrote:
>> 2010/7/1 B. Scott Smith<sc...@smithdomain.com>:
>>> The input stream it is returning is NULL. This only seems to happen 
>>> when I
>>> re-deploy into my Servlet Container (I am using Jetty). If I then 
>>> shut down
>>> the entire JVM and restart, the application runs fine.
>> What version of Jetty are you using? If you deploy it in, say, Tomcat,
>> does it work?
>>
>> Antonio
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: NullPointerException in init() during redeploy

Posted by "B. Scott Smith" <sc...@smithdomain.com>.
I am using Jetty 6.1.24 (latest stable release). I tried a much older 
version (Jetty 4.2.x) and the problem also occurs.
I am running JREv1.6, but it also fails on JREv1.4.2.
I will try to setup an environment to deploy it in Tomcat and see, but 
it may take a while.

In doing more tests, I have discovered some additional things.
First, I added a line in 
org.apache.velocity.runtime.RuntimeInstance#setDefaultProperties():

log.error("getResourceAsStream() returned null: 
"+getClass().getResource('/'+DEFAULT_RUNTIME_PROPERTIES));

and this shows a valid URL, so it is able to find the resource, but 
won't provide an inputStream to it. It prints:

getResourceAsStream() returned null:
   jar:file:<path to my 
app>/WEB-INF/lib/velocity-dep.jar!/org/apache/velocity/runtime/defaults/velocity.properties

Second, if I copy all of the default properties into my own 
velocity.properties file, and return with no error from 
setDefaultProperties(), it then blows up in initializeDirectives() with 
the same problem (inputStream is null). If I modify it to hardcode the 8 
properties from the directives.properties file and return, then my 
application runs fine. So, the ONLY issue is trying to load these 
properties files from the velocity-dep.jar, no other issues occur.
Somehow, my ClassLoader is getting messed up, and I can't figure out how 
to "reset" it.
  - Scott

On 7/1/2010 2:07 PM, Antonio Petrelli wrote:
> 2010/7/1 B. Scott Smith<sc...@smithdomain.com>:
>    
>> The input stream it is returning is NULL. This only seems to happen when I
>> re-deploy into my Servlet Container (I am using Jetty). If I then shut down
>> the entire JVM and restart, the application runs fine.
>>      
> What version of Jetty are you using? If you deploy it in, say, Tomcat,
> does it work?
>
> Antonio
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>    

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: NullPointerException in init() during redeploy

Posted by Antonio Petrelli <an...@gmail.com>.
2010/7/1 B. Scott Smith <sc...@smithdomain.com>:
> The input stream it is returning is NULL. This only seems to happen when I
> re-deploy into my Servlet Container (I am using Jetty). If I then shut down
> the entire JVM and restart, the application runs fine.

What version of Jetty are you using? If you deploy it in, say, Tomcat,
does it work?

Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org