Status: New
Owner: ----

New issue 396 by Greg.Lindholm: Struts2 plugin NPE if server bounced
http://code.google.com/p/google-guice/issues/detail?id=396

Guice 2.0, Struts 2.1.6, Tomcat 5.5

If the server (Tomcat) is started then stopped without any Guice activity
you get the exception below.

The problem is the 'delegate' member of
com.google.inject.struts2.GuiceObjectFactory.ProvidedInterceptor gets
created by the inject() method. If inject() is never called the destroy
() method throws the NPE.

destroy() needs to check if delegate is null before calling it.

java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: java.lang.NullPointerException
         at com.google.inject.struts2.GuiceObjectFactory
$ProvidedInterceptor.destroy(GuiceObjectFactory.java:216)
         at org.apache.struts2.dispatcher.Dispatcher.cleanup(Dispatcher.java:
287)
         at
org.apache.struts2.dispatcher.ng.PrepareOperations.cleanupDispatcher
(PrepareOperations.java:165)
         at
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.destroy
(StrutsPrepareAndExecuteFilter.java:84)
         at org.apache.catalina.core.ApplicationFilterConfig.release
(ApplicationFilterConfig.java:253)
         at org.apache.catalina.core.StandardContext.filterStop
(StandardContext.java:3670)
         at  
org.apache.catalina.core.StandardContext.stop(StandardContext.java:
4354)
         at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:
1067)
         at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:
1067)
         at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:
448)
         at  
org.apache.catalina.core.StandardService.stop(StandardService.java:
510)
         at org.apache.catalina.core.StandardServer.stop(StandardServer.java:
734)
         at org.apache.catalina.startup.Catalina.stop(Catalina.java:602)
         at org.apache.catalina.startup.Catalina.start(Catalina.java:577)
         ... 6 more

Here is a patch which seems to fix the problem.

Index: struts2/plugin/src/com/google/inject/struts2/
GuiceObjectFactory.java
===================================================================
--- struts2/plugin/src/com/google/inject/struts2/
GuiceObjectFactory.java (revision 1021)
+++ struts2/plugin/src/com/google/inject/struts2/
GuiceObjectFactory.java (working copy)
@@ -213,7 +213,9 @@
      }

      public void destroy() {
-      delegate.destroy();
+      if (delegate != null) {
+        delegate.destroy();
+      }
      }

      public void init() {

Attachments:
        patch.txt  524 bytes

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to