4 Replies Latest reply on Feb 6, 2014 6:57 PM by Alexander Hartner

    NullPointerException with Tomcat

    Iain Walsh Newbie

      Hi,

        I'm trying to use Weld(2.1.2 FINAL) with Tomcat (7.050). I've got a fairly basic Async Servlet set up. I'm injecting a Service object into the Servlet to handle all my Redis connections. Though at the moment the injected bean is just a standard POJO to test things.

       

      It runs fine but the Tomcat log always has this crash:

       

      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:71)

        at org.jboss.weld.context.http.HttpRequestContextImpl.deactivate(HttpRequestContextImpl.java:70)

        at org.jboss.weld.servlet.HttpContextLifecycle.requestDestroyed(HttpContextLifecycle.java:225)

        at org.jboss.weld.servlet.WeldInitialListener.requestDestroyed(WeldInitialListener.java:118)

        at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.requestDestroyed(ForwardingServletListener.java:38)

        at org.apache.catalina.core.StandardContext.fireRequestDestroyEvent(StandardContext.java:6151)

        at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:285)

        at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1636)

        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:599)

        at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)

        at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

        at java.lang.Thread.run(Thread.java:722)

       

      It looks similar to Weld-1020 on the issues board but that is marked as resolved in a previous version. So what might I be doing wrong?

       

      beans.xml is just an empty outline.

      context.xml is:

      <?xml version="1.0" encoding="UTF-8"?>

      <Context antiJARLocking="true" path="/ServiceName">

          <Resource name="BeanManager"

              auth="Container"

              type="javax.enterprise.inject.spi.BeanManager"

              factory="org.jboss.weld.resources.ManagerObjectFactory"/>

      </Context>

       

      web.xml is:

      <?xml version="1.0" encoding="UTF-8"?>

      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

               xmlns="http://java.sun.com/xml/ns/javaee"

               xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

                  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

               id="WebApp_ID" version="3.0">

          <listener>

             <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>

          </listener>

          <resource-env-ref>

              <resource-env-ref-name>BeanManager</resource-env-ref-name>

              <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>

          </resource-env-ref>

      </web-app>

       

      If it is failing to clean up objects at the end of the async handling then there will be issues with resource leaks and I'll be unable to use Weld.

       

      Any help is much appreciated. Thanks in advance.

        • 1. Re: NullPointerException with Tomcat
          bafco Newbie

          Hi Iain,

           

          even though WELD-1020 is marked as resolved, the example servlet in the "steps to Reproduce" still causes the exception given in the description.
          So you are doing nothing wrong. We'll have to look deeper into this.

           

          Matus

          • 3. Re: NullPointerException with Tomcat
            Iain Walsh Newbie

            Hmmm I am using NetBeans so that might be part of it. I'll investigate further, it doesn't seem to happen on our main deployment as we are doing that manually.

             

            Thanks.

             

            We've had a new issue with this callstack:

            java.lang.IllegalStateException: WELD-000335: Context is already active

              org.jboss.weld.context.http.LazyHttpConversationContextImpl.activate(LazyHttpConversationContextImpl.java:56)

              org.jboss.weld.servlet.ConversationContextActivator.activate(ConversationContextActivator.java:107)

              org.jboss.weld.servlet.ConversationContextActivator.activateConversationContext(ConversationContextActivator.java:93)

              org.jboss.weld.servlet.HttpContextLifecycle.requestInitialized(HttpContextLifecycle.java:183)

              org.jboss.weld.servlet.WeldInitialListener.requestInitialized(WeldInitialListener.java:153)

              org.jboss.weld.servlet.api.helpers.ForwardingServletListener.requestInitialized(ForwardingServletListener.java:42)

              org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)

              org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)

              org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)

              org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)

              org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)

              org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)

              java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

              java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

              java.lang.Thread.run(Thread.java:744)

             

            I've looked around and can't find WELD-000335 anywhere. Any idea what that is? Is it something to do with thread contexts as we are using Nio and Async.

             

            It just seems to happen almost randomly at points.

             

            I've not observed this one running locally on Tomcat 7.0.50 but our deployed server with 7.0.42 has. It may just be that my local machine isn't receiving the same load in test situations though.

            • 4. Re: NullPointerException with Tomcat
              Alexander Hartner Expert

              Have a look at the following post which covers the steps to reproduce:

               

              Re: Re: NPE in org.jboss.weld.environment.servlet.Listener

               

              In my case I found these exceptions in the localhost logs on tomcat.