0 Replies Latest reply on Mar 30, 2016 4:11 AM by tsukasa

    JCache annotations not working on constructors annotated with @Inject

    tsukasa Newbie

      Hello all,

       

      when we tried to switch from a hand writtten caching layer to JSR 107 compliant annotation-driven caching we encountered a serious problem:

      • We started at the quickstart provided here: infinispan-quickstart/cdi at master · infinispan/infinispan-quickstart · GitHub which worked well in the beginning.
      • Our tests are Running on JBoss EAP 6.4 - so we tweeked the jboss-deployment-structure.xml to exclude hibernate module dependcies as described here Bug 1202911 – [GSS](6.4.z) Class loader loads extra services from modules
      • Problems started when we try to use @CacheResult for stateless beans with a constructor annotated with @Inject and a non-empty parameter list (as we prefer services with explicit contract this is more than 80%).
        • During server startup we faced a NullPointerException without any visible context.
        • Using TRACE(!?!)-logging and finally some well-chosen breakpoints we narrowed down the issue to WeldConstructorImpl.java:70 where null is passed as "annotatedConstructor" (param 1) - cmp stacktrace below.
        • This is a result of the proxy generation for the @Local bean interface of the bean implementation to create.
      • In the sample attached you'll find 2 eclipse projects:
        • one representing the ear project ("com.example.app") ,
        • the other representing the ejb project ("com.example.jcache").
        • Any dependencies not provided by JBoss AS are bundled within com.example.app/EarContent/lib
      • To get the example performing "well" you just need to disable the constructor com.example.jcache.GreetingService.GreetingService(LocalInjectableService) and enable the @EJB injection of the bean.

       

      09:03:56,578 TRACE [weld.Bean] (MSC service thread 1-4) Retrieving/generating proxy class com.example.jcache.CacheManagerLocal$212228337$Proxy$_$$_WeldSubclass

      09:03:56,579 TRACE [weld.Bean] (MSC service thread 1-4) Adding method public abstract void com.example.jcache.CacheManagerLocal.clearCache()

      09:03:56,579 TRACE [weld.Bean] (MSC service thread 1-4) Adding method public abstract java.lang.String com.example.jcache.CacheManagerLocal.greet(java.lang.String)

      09:03:56,579 TRACE [weld.Bean] (MSC service thread 1-4) Adding method public abstract int com.example.jcache.CacheManagerLocal.getNumberOfEntries()

      09:03:56,579 TRACE [weld.Bean] (MSC service thread 1-4) Adding method public abstract java.lang.String com.example.jcache.CacheManagerLocal.getCacheName()

      09:03:56,580 TRACE [weld.Bean] (MSC service thread 1-4) Adding method public abstract org.infinispan.eviction.EvictionStrategy com.example.jcache.CacheManagerLocal.getEvictionStrategy()

      09:03:56,580 TRACE [weld.Bean] (MSC service thread 1-4) Adding method public abstract int com.example.jcache.CacheManagerLocal.getEvictionMaxEntries()

      09:03:56,580 TRACE [weld.Bean] (MSC service thread 1-4) Adding method public abstract void org.jboss.weld.interceptor.proxy.LifecycleMixin.lifecycle_mixin_$$_preDestroy()

      09:03:56,580 TRACE [weld.Bean] (MSC service thread 1-4) Adding method public abstract void org.jboss.weld.interceptor.proxy.LifecycleMixin.lifecycle_mixin_$$_postConstruct()

      09:03:56,581 TRACE [weld.Bean] (MSC service thread 1-4) Created Proxy class of type class com.example.jcache.CacheManagerLocal$212228337$Proxy$_$$_WeldSubclass supporting interfaces [interface com.example.jcache.CacheManagerLocal, interface java.io.Serializable, interface org.jboss.weld.interceptor.proxy.LifecycleMixin, interface org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy, interface javassist.util.proxy.ProxyObject]

      09:03:56,581 ERROR [service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."com.example.app.ear".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."com.example.app.ear".WeldStartService: Failed to start service

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1936) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_79]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_79]

          at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]

      Caused by: java.lang.NullPointerException

          at org.jboss.weld.introspector.jlr.WeldConstructorImpl.of(WeldConstructorImpl.java:70)

          at org.jboss.weld.bean.AbstractClassBean.initEnhancedSubclass(AbstractClassBean.java:462)

          at org.jboss.weld.bean.AbstractClassBean.initializeAfterBeanDiscovery(AbstractClassBean.java:189)

          at org.jboss.weld.bean.SessionBean.initializeAfterBeanDiscovery(SessionBean.java:208)

          at org.jboss.weld.bootstrap.BeanDeployment.doAfterBeanDiscovery(BeanDeployment.java:229)

          at org.jboss.weld.bootstrap.BeanDeployment.afterBeanDiscovery(BeanDeployment.java:221)

          at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:365)

          at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:63)

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1980) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

          at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1913) [jboss-msc-1.1.5.Final-redhat-1.jar:1.1.5.Final-redhat-1]

          ... 3 more

       

      09:03:56,586 ERROR [controller.management-operation] (Controller Boot Thread) JBAS014612: Operation ("deploy") fehlgeschlagen - Adresse: ([("deployment" => "com.example.app.ear")]) - Fehlerbeschreibung: {"JBAS014671: Fehlgeschlagene Dienste" => {"jboss.deployment.unit.\"com.example.app.ear\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"com.example.app.ear\".WeldStartService: Failed to start service

          Caused by: java.lang.NullPointerException"}}