glassfish
  1. glassfish
  2. GLASSFISH-19083

org.jboss.weld.context.ContextNotActiveException is thrown when undeploying application.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 4.0_dev
    • Fix Version/s: 4.0
    • Component/s: cdi
    • Labels:
      None

      Description

      There are 2 beans A and B. A is dependent scoped and B is request scoped. B is injected into A. A is injected into an EJB.

      To reproduce, please refer to the attached netbean project.

      1. Build and deploy the ear.
      2. Access the NewServlet via browser for initializing an EJB instance.
      3. Undeploy the application to trigger bean A's preDestroy method. Then we can see the following exception.

      [#|2012-09-17T15:03:12.609+0800|INFO|44.0|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=13;_ThreadName=admin-listener(2);|EnterpriseApplication1 was successfully deployed in 785 milliseconds.|#]

      [#|2012-09-17T15:03:16.706+0800|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=http-listener-1(2);|B.xyz() is called.|#]

      [#|2012-09-17T15:03:36.931+0800|INFO|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=13;_ThreadName=admin-listener(2);|A is closing...|#]

      [#|2012-09-17T15:03:36.933+0800|SEVERE|44.0|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=13;_ThreadName=admin-listener(2);|org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.RequestScoped
      at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:598)
      at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
      at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
      at test.B$Proxy$$$_WeldClientProxy.close(B$Proxy$$$_WeldClientProxy.java)
      at test.A.cleanup(A.java:28)
      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.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
      at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
      at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
      at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
      at org.jboss.weld.introspector.jlr.WeldMethodImpl.invoke(WeldMethodImpl.java:174)
      at org.jboss.weld.bean.AbstractClassBean.defaultPreDestroy(AbstractClassBean.java:493)
      at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.preDestroy(ManagedBean.java:182)
      at org.jboss.weld.bean.ManagedBean.destroy(ManagedBean.java:302)
      at org.jboss.weld.context.ForwardingContextual.destroy(ForwardingContextual.java:31)
      at org.jboss.weld.context.CreationalContextImpl.destroy(CreationalContextImpl.java:100)
      at org.jboss.weld.context.CreationalContextImpl.release(CreationalContextImpl.java:92)
      at org.jboss.weld.context.CreationalContextImpl.release(CreationalContextImpl.java:83)
      at org.glassfish.weld.services.JCDIServiceImpl$JCDIInjectionContextImpl.cleanup(JCDIServiceImpl.java:318)
      at com.sun.ejb.containers.BaseContainer.cleanupInstance(BaseContainer.java:1704)
      at com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.destroy(StatelessSessionContainer.java:779)
      at com.sun.ejb.containers.util.pool.NonBlockingPool.close(NonBlockingPool.java:417)
      at com.sun.ejb.containers.StatelessSessionContainer.doConcreteContainerShutdown(StatelessSessionContainer.java:709)
      at com.sun.ejb.containers.BaseContainer.undeploy(BaseContainer.java:4163)
      at org.glassfish.ejb.startup.EjbApplication.stop(EjbApplication.java:297)
      at org.glassfish.internal.data.EngineRef.stop(EngineRef.java:161)
      at org.glassfish.internal.data.ModuleInfo.stop(ModuleInfo.java:311)
      at org.glassfish.internal.data.ApplicationInfo.stop(ApplicationInfo.java:327)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.unload(ApplicationLifecycle.java:1051)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.undeploy(ApplicationLifecycle.java:1091)
      at org.glassfish.deployment.admin.UndeployCommand.execute(UndeployCommand.java:399)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:529)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:550)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1430)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1600(CommandRunnerImpl.java:114)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1734)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1683)
      at org.glassfish.admin.rest.resources.admin.CommandResource.executeCommand(CommandResource.java:467)
      at org.glassfish.admin.rest.resources.admin.CommandResource.execCommandSimpInMultOut(CommandResource.java:255)
      at sun.reflect.GeneratedMethodAccessor117.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.glassfish.jersey.server.model.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:80)
      at org.glassfish.jersey.server.model.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:113)
      at org.glassfish.jersey.server.model.AbstractJavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(AbstractJavaResourceMethodDispatcherProvider.java:176)
      at org.glassfish.jersey.server.model.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:268)
      at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:84)
      at org.glassfish.jersey.process.internal.RequestInvoker$AcceptingInvoker.apply(RequestInvoker.java:241)
      at org.glassfish.jersey.process.internal.AsyncInflectorAdapter.apply(AsyncInflectorAdapter.java:157)
      at org.glassfish.jersey.process.internal.RequestInvoker$2.run(RequestInvoker.java:188)
      at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:309)
      at org.glassfish.jersey.process.internal.RequestInvoker$3.run(RequestInvoker.java:201)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:262)
      at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:43)
      at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:40)
      at org.glassfish.jersey.process.internal.RequestInvoker.apply(RequestInvoker.java:197)
      at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:758)
      at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:298)
      at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:205)
      at com.sun.enterprise.v3.server.HK2Dispatcher.dispatch(HK2Dispatcher.java:113)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:236)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:164)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:175)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:825)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:578)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:558)
      at java.lang.Thread.run(Thread.java:662)

      #]

        Activity

        Hide
        arjavdesai added a comment -

        It seem to have been fixed as destroy of context is not getting invoked twice but I am not able to pin-point exact revision which fixed it. I was able to but now can't re-produce the issue with Glassfish build with revision's upto 60839. Please re-try, if you would.

        Show
        arjavdesai added a comment - It seem to have been fixed as destroy of context is not getting invoked twice but I am not able to pin-point exact revision which fixed it. I was able to but now can't re-produce the issue with Glassfish build with revision's upto 60839. Please re-try, if you would.
        Hide
        David Zhao added a comment -

        I can still reproduce it with revision 60914 by the attached application.

        Show
        David Zhao added a comment - I can still reproduce it with revision 60914 by the attached application.
        Hide
        arjavdesai added a comment -

        David,

        I downloaded GFS 4.0 promoted build 82 from http://dlc.sun.com.edgesuite.net/glassfish/4.0/nightly/glassfish-4.0-b82-03_26_2013.zip and deployed ear (already built in your zip file upload) without any error i.e.

        [2013-03-27T11:02:49.549-0400] [glassfish 4.0] [INFO] [] [org.glassfish.admingui] [tid: _ThreadID=45 _ThreadName=admin-listener(4)] [timeMillis: 1364396569549] [levelValue: 800] [[
        Admin Console: Initializing Session Attributes...]]

        [2013-03-27T11:03:28.958-0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396608958] [levelValue: 800] [[
        Snifer org.glassfish.javaee.full.deployment.EarSniffer@188b9 set up following modules: []]]

        [2013-03-27T11:03:29.100-0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609100] [levelValue: 800] [[
        Snifer org.glassfish.ejb.deployment.archive.EjbSniffer@189c0 set up following modules: []]]

        [2013-03-27T11:03:29.112-0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609112] [levelValue: 800] [[
        Snifer org.glassfish.weld.connector.WeldSniffer@37a229 set up following modules: []]]

        [2013-03-27T11:03:29.195-0400] [glassfish 4.0] [INFO] [ejb.portable_jndi_names] [javax.enterprise.system.container.ejb.com.sun.ejb.containers] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609195] [levelValue: 800] [[
        EJB5181:Portable JNDI names for EJB NewSessionBean: [java:global/EnterpriseApplication1/EnterpriseApplication1-ejb/NewSessionBean, java:global/EnterpriseApplication1/EnterpriseApplication1-ejb/NewSessionBean!test.NewSessionBean]]]

        [2013-03-27T11:03:29.269-0400] [glassfish 4.0] [INFO] [] [org.jboss.weld.Version] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609269] [levelValue: 800] [[
        WELD-000900 2.0.0 (Beta6)]]

        [2013-03-27T11:03:29.975-0400] [glassfish 4.0] [WARNING] [] [org.jboss.weld.interceptor.util.InterceptionTypeRegistry] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609975] [levelValue: 900] [[
        Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled]]

        [2013-03-27T11:03:29.976-0400] [glassfish 4.0] [WARNING] [] [org.jboss.weld.interceptor.util.InterceptionTypeRegistry] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609976] [levelValue: 900] [[
        Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled]]

        [2013-03-27T11:03:30.273-0400] [glassfish 4.0] [INFO] [AS-WEB-GLUE-00172] [javax.enterprise.web] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396610273] [levelValue: 800] [[
        Loading application EnterpriseApplication1#EnterpriseApplication1-war.war at [EnterpriseApplication1-war]]]

        [2013-03-27T11:03:30.346-0400] [glassfish 4.0] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396610346] [levelValue: 800] [[
        EnterpriseApplication1 was successfully deployed in 1,478 milliseconds.]]

        Show
        arjavdesai added a comment - David, I downloaded GFS 4.0 promoted build 82 from http://dlc.sun.com.edgesuite.net/glassfish/4.0/nightly/glassfish-4.0-b82-03_26_2013.zip and deployed ear (already built in your zip file upload) without any error i.e. [2013-03-27T11:02:49.549-0400] [glassfish 4.0] [INFO] [] [org.glassfish.admingui] [tid: _ThreadID=45 _ThreadName=admin-listener(4)] [timeMillis: 1364396569549] [levelValue: 800] [[ Admin Console: Initializing Session Attributes...]] [2013-03-27T11:03:28.958-0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396608958] [levelValue: 800] [[ Snifer org.glassfish.javaee.full.deployment.EarSniffer@188b9 set up following modules: []]] [2013-03-27T11:03:29.100-0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609100] [levelValue: 800] [[ Snifer org.glassfish.ejb.deployment.archive.EjbSniffer@189c0 set up following modules: []]] [2013-03-27T11:03:29.112-0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609112] [levelValue: 800] [[ Snifer org.glassfish.weld.connector.WeldSniffer@37a229 set up following modules: []]] [2013-03-27T11:03:29.195-0400] [glassfish 4.0] [INFO] [ejb.portable_jndi_names] [javax.enterprise.system.container.ejb.com.sun.ejb.containers] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609195] [levelValue: 800] [[ EJB5181:Portable JNDI names for EJB NewSessionBean: [java:global/EnterpriseApplication1/EnterpriseApplication1-ejb/NewSessionBean, java:global/EnterpriseApplication1/EnterpriseApplication1-ejb/NewSessionBean!test.NewSessionBean] ]] [2013-03-27T11:03:29.269-0400] [glassfish 4.0] [INFO] [] [org.jboss.weld.Version] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609269] [levelValue: 800] [[ WELD-000900 2.0.0 (Beta6)]] [2013-03-27T11:03:29.975-0400] [glassfish 4.0] [WARNING] [] [org.jboss.weld.interceptor.util.InterceptionTypeRegistry] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609975] [levelValue: 900] [[ Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled]] [2013-03-27T11:03:29.976-0400] [glassfish 4.0] [WARNING] [] [org.jboss.weld.interceptor.util.InterceptionTypeRegistry] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396609976] [levelValue: 900] [[ Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled]] [2013-03-27T11:03:30.273-0400] [glassfish 4.0] [INFO] [AS-WEB-GLUE-00172] [javax.enterprise.web] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396610273] [levelValue: 800] [[ Loading application EnterpriseApplication1#EnterpriseApplication1-war.war at [EnterpriseApplication1-war] ]] [2013-03-27T11:03:30.346-0400] [glassfish 4.0] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=44 _ThreadName=admin-listener(3)] [timeMillis: 1364396610346] [levelValue: 800] [[ EnterpriseApplication1 was successfully deployed in 1,478 milliseconds.]]
        Hide
        David Zhao added a comment -

        arjavdesai:

        As what I wrote in the description, the exception doesn't occur at deployment, but happens at undeployment. Please follow the steps to reproduce.

        Show
        David Zhao added a comment - arjavdesai: As what I wrote in the description, the exception doesn't occur at deployment, but happens at undeployment. Please follow the steps to reproduce.
        Hide
        arjavdesai added a comment -

        David:

        Undeploy also works fine:

        [2013-03-28T09:12:29.374-0400] [glassfish 4.0] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=46 _ThreadName=admin-listener(4)] [timeMillis: 1364476349374] [levelValue: 800] [[
        EnterpriseApplication1 was successfully deployed in 1,709 milliseconds.]]

        [2013-03-28T09:12:36.196-0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=136 _ThreadName=Thread-3] [timeMillis: 1364476356196] [levelValue: 800] [[

          • BatchRuntimeHelper:: App Undeployed: EnterpriseApplication1]]

        Did you try it out with the glassfish from the URL link?

        Show
        arjavdesai added a comment - David: Undeploy also works fine: [2013-03-28T09:12:29.374-0400] [glassfish 4.0] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=46 _ThreadName=admin-listener(4)] [timeMillis: 1364476349374] [levelValue: 800] [[ EnterpriseApplication1 was successfully deployed in 1,709 milliseconds.]] [2013-03-28T09:12:36.196-0400] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=136 _ThreadName=Thread-3] [timeMillis: 1364476356196] [levelValue: 800] [[ BatchRuntimeHelper:: App Undeployed: EnterpriseApplication1]] Did you try it out with the glassfish from the URL link?
        Hide
        David Zhao added a comment -

        arjavdesai,

        Still this can be reproduced with nightly build glassfish-4.0-b83-03_28_2013.zip.

        Can you elaborate the steps you used for reproduction? Did you follow my step <2> "Access the NewServlet via browser for initializing an EJB instance" which was mentioned in the description previously before undeployment? That is essential to reproduce the problem. To be more specific, you need access the servlet by http://localhost:8080/EnterpriseApplication1-war/NewServlet to initialize an ejb instance which has bean injected, and then undeploy the ear.

        Show
        David Zhao added a comment - arjavdesai, Still this can be reproduced with nightly build glassfish-4.0-b83-03_28_2013.zip. Can you elaborate the steps you used for reproduction? Did you follow my step <2> "Access the NewServlet via browser for initializing an EJB instance" which was mentioned in the description previously before undeployment? That is essential to reproduce the problem. To be more specific, you need access the servlet by http://localhost:8080/EnterpriseApplication1-war/NewServlet to initialize an ejb instance which has bean injected, and then undeploy the ear.
        Hide
        arjavdesai added a comment -

        As per spec and as mentioned in javadoc, http://docs.oracle.com/javaee/6/api/javax/enterprise/context/RequestScoped.html, the request context is not active during the life cycle method's of a bean i.e. PreDestroy in this case. If you need to have a business need for this, the suggested approach is to have PreDestroy method in RequestScoped bean itself rather than calling it from PreDestroy (life cycle) method if another bean.

        Show
        arjavdesai added a comment - As per spec and as mentioned in javadoc, http://docs.oracle.com/javaee/6/api/javax/enterprise/context/RequestScoped.html , the request context is not active during the life cycle method's of a bean i.e. PreDestroy in this case. If you need to have a business need for this, the suggested approach is to have PreDestroy method in RequestScoped bean itself rather than calling it from PreDestroy (life cycle) method if another bean.

          People

          • Assignee:
            arjavdesai
            Reporter:
            David Zhao
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: