Link to home
Start Free TrialLog in
Avatar of Sabooji
SaboojiFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I resolve Tomcat 6 experiencing a NullPointerException when attempting to invoke contextDestroyed()?

Hi,

I have a context listener extending ServletContextListener. I use contextInitialized() to load in my application's property file and spawn a new thread for managing an external resource; contextDestroyed() is used to gracefully stop this thread from managing the resource.

When Tomcat starts up, contextInitialized() is invoked as expected and the application loads normally. Upon stopping the application / shutting down Tomcat, Catalina throws a NullPointerException when attempting to pass my context listener the "context destroyed" event.

I've included the error from my 'localhost' logfile.

I've checked the "standard" things, such as ensuring my application isn't throwing exceptions, no duplicate .jar's within the lib directories.

Any idea as to why Tomcat is experiencing the NullPointer?
02-Jul-2009 23:00:12 org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class fivestarlives.ApplicationContextListener
java.lang.NullPointerException
	at fivestarlives.ApplicationContextListener.contextDestroyed(Unknown Source)
	at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3973)
	at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4577)
	at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:924)
	at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1248)
	at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1219)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:316)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
	at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1086)
	at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
	at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:448)
	at org.apache.catalina.core.StandardService.stop(StandardService.java:584)
	at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
	at org.apache.catalina.startup.Catalina.stop(Catalina.java:633)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:608)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial