9 Replies Latest reply on Mar 3, 2010 8:28 AM by Ian R

    Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2

    Ian R Newbie

      Hi, I've just downloaded the new JBoss release and upgraded the version of Weld in it. So I've restored my code which injects a logger into a ServletContextListener (took it out once I found out M1 didn't support injections in the web container). I can see the container calling my @Producer, but after the caller is called and before it gets back to the method in the class (the contextInitialised() method) I get the following stack trace. Does anybody have any ideas?


      Thanks,


      Ian





      10:01:04,050 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/optin]] Error configuring application listener of class my.package.ApplicationInitialisation: java.lang.NullPointerException
           at org.jboss.weld.util.Beans.isPassivatingScope(Beans.java:132)
           at org.jboss.weld.bean.AbstractProducerBean.checkReturnValue(AbstractProducerBean.java:263)
           at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:349)
           at org.jboss.weld.context.DependentContext.get(DependentContext.java:62)
           at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:788)
           at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:850)
           at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:874)
           at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:108)
           at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:775)
           at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:787)
           at org.jboss.weld.manager.SimpleInjectionTarget$1.proceed(SimpleInjectionTarget.java:122)
           at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:51)
           at org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:116)
           at org.jboss.weld.integration.injection.NonContextualObjectInjectionHelper.injectNonContextualInstance(NonContextualObjectInjectionHelper.java:22)
           at org.jboss.weld.integration.injection.WeldInjector.inject(WeldInjector.java:39)
           at org.jboss.web.tomcat.service.TomcatInjectionContainer.processInjectors(TomcatInjectionContainer.java:388)
           at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:284)
           at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:278)
           at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:261)
           at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3876)
           at org.apache.catalina.core.StandardContext.start(StandardContext.java:4447)
           at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:315)
           at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:145)
           at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:462)
           at org.jboss.web.deployers.WebModule.startModule(WebModule.java:116)
           at org.jboss.web.deployers.WebModule.start(WebModule.java:95)
           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.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)
           at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)
           at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
           at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:271)
           at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:670)
           at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)
           at $Proxy41.start(Unknown Source)
           at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:53)
           at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:41)
           at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
           at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
           at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
           at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:378)
           at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:301)
           at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2029)
           at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1050)
           at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1289)
           at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1213)
           at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1107)
           at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:918)
           at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:633)
           at org.jboss.system.ServiceController.doChange(ServiceController.java:671)
           at org.jboss.system.ServiceController.start(ServiceController.java:443)
           at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:189)
           at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:102)
           at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:49)
           at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
           at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55)
           at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1660)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1378)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1399)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1431)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1319)
           at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:378)
           at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2029)
           at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1050)
           at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1289)
           at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1213)
           at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1107)
           at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:918)
           at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:633)
           at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:898)
           at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:677)
           at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
           at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:409)
           at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:294)
           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
           at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
           at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
           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)


        • 1. Re: Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2
          Nicklas Karlsson Master

          Could you show some code? The exception apparently comes from


                  return manager.getServices().get(MetaAnnotationStore.class).getScopeModel(bean.getScope()).isPassivating();
          



          when the producer method checks the produced return value with


                  if (!instanceSerializable && Beans.isPassivatingScope(injectionPoint.getBean(), beanManager))
          



          so is it possible somehow that the bean of the injection point returns a scope that isn't known to Weld?

          • 2. Re: Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2
            Ian R Newbie

            I didn't include code as I thought it was rather trivial - might be trivial to me, but not to others I'm sure!


            Firstly a fragment from the ContextListener:


            public class ApplicationInitialisation
                 implements ServletContextListener {
            
                @Inject
                private OptinService optinServices;
            
                @Inject
                private Logger log;
            
                /**
                 * @see ServletContextListener#contextInitialized(ServletContextEvent)
                 */
                public void contextInitialized(ServletContextEvent event) {
                 ContainerInitializer.initialize();
                 log.debug("Web container initialised successfully.");
                 optinServices.initializeContainer();
                 log.debug("EJB container initialised successfully.");
                }
            
            etc etc
            
            }



            Note that the first injection statement (an EJB) works properly, so it's unlikely to be that the class can't be injected into (like it was in M1).


            Now the logger (based on the documentation example but using log4j):


            public class LoggingFactory {
                @Produces
                Logger createLogger(InjectionPoint injectionPoint) {
                 return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
                }
            }



            Not much else to it.



            Thanks,


            Ian







            • 3. Re: Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2
              Nicklas Karlsson Master

              All in one WAR? What does injectionPoint.getBean() say if you output it in the producer?

              • 4. Re: Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2
                Ian R Newbie

                The application is in a EAR file. The EJB is in its own EJB jar file. The initialisation class is in the WAR file, and the LoggingFactory class is in a utility jar (which is in the lib/ directory of the EAR file).


                If you System.out(injectionPoint.getBean()) the result is null.


                • 5. Re: Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2
                  Ian R Newbie

                  I don't think the issue is to do with JBoss 6.0.0 M2, but it might have something to do with the Logger and the injection happening with that.


                  Why do I say this? I was trying to get around a problem with injection in a JSF ExceptionHandler. The factory is not a managed bean and I wanted it to produce a class that at least has things injected into it (even if it isn't managed). I injected two classes into it - a POJO which is rather boring, and an instance of the logger class. I introduced the injection one class at a time. The POJO was injected successfully. However when I inject the logger, I get a stacktrace which looks somewhat familiar:





                  java.lang.NullPointerException
                       org.jboss.weld.util.Beans.isPassivatingScope(Beans.java:132)
                       org.jboss.weld.bean.AbstractProducerBean.checkReturnValue(AbstractProducerBean.java:263)
                       org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:349)
                       org.jboss.weld.context.DependentContext.get(DependentContext.java:62)
                       org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:788)
                       org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:850)
                       org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:874)
                       org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:108)
                       org.jboss.weld.util.Beans.injectBoundFields(Beans.java:775)
                       org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:787)
                       org.jboss.weld.manager.SimpleInjectionTarget$1.proceed(SimpleInjectionTarget.java:122)
                       org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:51)
                       org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:116)
                       my.package.ui.DisplayExceptionHandlerFactory.getExceptionHandler(DisplayExceptionHandlerFactory.java:40)
                       com.sun.faces.context.FacesContextFactoryImpl.getFacesContext(FacesContextFactoryImpl.java:98)
                       javax.faces.webapp.FacesServlet.service(FacesServlet.java:302)
                       org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:66)

                  Maybe it has something to do with the injection of that logger.


                  The code I was using to do the injection is below:





                  public class DisplayExceptionHandlerFactory
                       extends ExceptionHandlerFactory {
                  
                      private ExceptionHandlerFactory parent;
                      private InjectionTarget<DisplayExceptionHandler> injectionTarget;
                      private CreationalContext<DisplayExceptionHandler> instanceContext;
                  
                      public DisplayExceptionHandlerFactory(ExceptionHandlerFactory parent) {
                       this.parent = parent;
                       // Set things up so we are ready to inject our beans with dependent fields
                       BeanManager beanManager = InjectionResourceFactory.getBeanManagerResource();
                       AnnotatedType<DisplayExceptionHandler> type = beanManager.createAnnotatedType(DisplayExceptionHandler.class);
                       injectionTarget = beanManager.createInjectionTarget(type);
                       instanceContext = beanManager.createCreationalContext(null);
                      }
                  
                      @Override
                      public ExceptionHandler getExceptionHandler() {
                       ExceptionHandler result = parent.getExceptionHandler();
                  
                       DisplayExceptionHandler handler = new DisplayExceptionHandler(result);
                       injectionTarget.postConstruct(handler);
                  
                       return handler;
                      }
                  }
                  



                  And injectionPoint.getBean() is returning null again.

                  • 6. Re: Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2
                    Pete Muir Master

                    Ok, please report an issue in JIRA with the relevant bits of code distilled down to something we can test easily (e.g. no dependencies on JSF etc.)


                    I suspect I might have fixed this in trunk, as I changed that code around a bit.

                    • 7. Re: Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2
                      Ian R Newbie

                      Ok, I've created WELD-445. The ServletContextListener example is pretty simple so I included that.


                      How do I get a copy of the trunk so I can test it out to ensure it is fixed? Then I can verify your fix.

                      • 8. Re: Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2
                        Nicklas Karlsson Master

                        You can check if Hudson has managed to spit out something useful

                        • 9. Re: Problem with JBoss 6.0.0 M2 and Weld 1.0.1 CR2
                          Ian R Newbie

                          No wonder you can't reproduce it - I can't since I upgraded to 1.0.1 Final. So your fixes to the trunk did the trick. Thanks for that Pete.