frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Struts2 plugin NPE if server bounced #396

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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() { 

Original issue reported on code.google.com by Greg.Lin...@gmail.com on 26 Jun 2009 at 2:38

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for reporting this!

Btw, note that I've rewritten the struts2 plugin altogether (it now works 
properly with Guice Servlet2 and it 
doesn't do evil things like catch Throwable). But I have made the fix in both 
versions of the plugin.

Original comment by dha...@gmail.com on 27 Jun 2009 at 1:01

GoogleCodeExporter commented 9 years ago
Hi all,

This issue also has the effect of causing a failed hot deployment in JBoss if 
you go 
to redeploy the application without any previous Guice activity.  I'm hoping to 
get 
a point release containing this fix (instead of managing my own patch build of 
Guice).  Any idea when a next build will come?

Thanks,
Tom

Original comment by busin...@tmckinney.com on 17 Aug 2009 at 8:07

GoogleCodeExporter commented 9 years ago
The fix is in trunk, you can take a snapshot from trunk and use it?

Original comment by dha...@gmail.com on 18 Aug 2009 at 12:18

GoogleCodeExporter commented 9 years ago
I have encountered another issue on snapshot. I guess reporting this here is
preferable to open a new issue against snapshot.

I have build guice from snapshot (15 minutes ago), and replaced guice-struts 
plugin
with the newly built one.

Guice cannot instantiate empty Actions like these:

<action name="UserAdd">
  <result>userAdd.jsp</result>
</action>

Returns with this exception:

Struts Problem Report
Struts has detected an unhandled exception: 

Messages: Unable to instantiate Action, com.opensymphony.xwork2.ActionSupport,
defined for 'UserAdd' in namespace '/'null 

As you know, ActionSupport is not an abstract class.

Original comment by bahri.ge...@gmail.com on 8 Feb 2010 at 3:35

GoogleCodeExporter commented 9 years ago
Full stack trace.

Original comment by bahri.ge...@gmail.com on 8 Feb 2010 at 4:16

Attachments: