0 Replies Latest reply on Mar 15, 2011 12:23 PM by Dorin Balaban

    NullPointerException in Tomcat on Weld servlet listener

    Dorin Balaban Newbie

      Hello,


      I've created a simple test case web application that uses:



      • Tomcat 7.0.11

      • JSF 2 (Mojarra JSF Implementation 2.0.4)

      • Weld 1.1.0.Final



      The application uses FORM authentication. When running the application for the first time, the Tomcat authentication mechanism forwards to login page. The page displays correctly, but the following exception is being thrown:



      SEVERE: Exception sending request initialized lifecycle event to listener instance of class org.jboss.weld.environment.servlet.Listener
      java.lang.NullPointerException
           at org.jboss.weld.context.AbstractBoundContext.deactivate(AbstractBoundContext.java:81)
           at org.jboss.weld.servlet.WeldListener.requestDestroyed(WeldListener.java:115)
           at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.requestDestroyed(ForwardingServletListener.java:42)
           at org.apache.catalina.core.StandardContext.fireRequestDestroyEvent(StandardContext.java:5937)
           at org.apache.catalina.authenticator.FormAuthenticator.forwardToLoginPage(FormAuthenticator.java:374)
           at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:267)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:556)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
           at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
           at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
           at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
           at java.lang.Thread.run(Thread.java:619)
      




      I should mention that in my context.xml I use the new context attribute fireRequestListenersOnForwards, introduced in Tomcat since the version 7.0.9:


      <Context fireRequestListenersOnForwards="true">
      </Context>



      This attribute was introduced in Tomcat to enable CDI frameworks' ServletRequestListeners to be fired on forwards. There was a bug regarding this issue and it was fixed. You may look for details here https://issues.apache.org/bugzilla/show_bug.cgi?id=50789.


      Also, there is a custom 404 page that is defined like this:


          <error-page>
              <error-code>404</error-code>
              <location>/404.xhtml</location>
          </error-page> 



      So, if  I set

      fireRequestListenersOnForwards="false"

      , the NullPointerException is not thrown, but if I provoke a 404 error, by going to an inexistent location, my custom page doesn't get displayed and I see the same error as in the bug issue 50789 referred above.


      I wonder if it is a Tomcat bug or a Weld integration problem and, in this latter case, should I file a JIRA...?


      Note:

      If I change 404.xhtml to 404.html, thus disengaging the JSF servlet, then no exception is thrown.