That's ApplicationBoundaryService role ;)
Romain Manni-Bucau @rmannibucau <https://twitter.com/rmannibucau> | Blog <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> | LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber <http://www.tomitribe.com> 2016-02-16 9:11 GMT+01:00 Xavier Dury <[email protected]>: > Just some crazy thought: do you think that a getClassLoader() method (to > provide the ClassLoader to use when proxying) > on javax.enterprise.inject.spi.Bean could help solve that kind of problem? > It could default to getBeanClass().getClassLoader(). > > ---------------------------------------- > > From: [email protected] > > To: [email protected] > > Subject: RE: NPE when creating a bean through Extension and not through > Producer > > Date: Tue, 16 Feb 2016 08:48:25 +0100 > > > > Ok, thanks for the clarification! > > > > ---------------------------------------- > >> From: [email protected] > >> Date: Tue, 16 Feb 2016 08:44:31 +0100 > >> Subject: Re: NPE when creating a bean through Extension and not through > Producer > >> To: [email protected] > >> > >> Side note: @CdiExtensions(EmptyExtension.class) = @CdiExtensions({}) = > >> @CdiExtensions normally > >> > >> Difference is the classloader for the producer is the one of the > producer > >> instance and not the returned type (JAXContextProducer in your sample) > >> > >> > >> > >> > >> Romain Manni-Bucau > >> @rmannibucau <https://twitter.com/rmannibucau> | Blog > >> <http://rmannibucau.wordpress.com> | Github < > https://github.com/rmannibucau> | > >> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber > >> <http://www.tomitribe.com> > >> > >> 2016-02-16 8:36 GMT+01:00 Xavier Dury <[email protected]>: > >> > >>> Thanks for your answer, > >>> > >>> I had doubts it had something to do with the proxying of the > JAXBContext > >>> but what I don't understand is why the @Produced one does not have this > >>> problem. Are @Produced @ApplicationScoped beans not proxied? > >>> > >>> Xavier > >>> > >>> ---------------------------------------- > >>>> From: [email protected] > >>>> Date: Tue, 16 Feb 2016 08:25:06 +0100 > >>>> Subject: Re: NPE when creating a bean through Extension and not > through > >>> Producer > >>>> To: [email protected] > >>>> > >>>> Hi Xavier, > >>>> > >>>> it comes from the fact you scoped the context (@ApplicationScoped) so > >>>> openwebbeans needs to generate a proxy in the classloader of jaxb > which > >>> is > >>>> probably null there - depends where it is so embedded vs tomee can be > >>>> important there. > >>>> > >>>> The workaround is trivial: wrap the context in an ApplicationScoped > bean > >>> or > >>>> simply use the producer instance (not the produced one) and create the > >>>> context in @PostConstruct and in the @Produces always return the same > >>>> instance. > >>>> > >>>> This has a nice side effect: it prevents leaks cause classes not > >>> belonging > >>>> in the application and proxied can leak generally cause some of them > need > >>>> to be in the same classloader as the proxied class itself cause of > java > >>>> rules - whatever container it is. > >>>> > >>>> That said we can get a better exception on openwebbeans. An > alternative > >>> fix > >>>> is probably to override ApplicationBoundaryService of openwebbeans in > >>> your > >>>> application (openwebbeans.properties) but this sounds more fragile > than > >>> the > >>>> previous workaround which is safe. > >>>> > >>>> > >>>> > >>>> Romain Manni-Bucau > >>>> @rmannibucau <https://twitter.com/rmannibucau> | Blog > >>>> <http://rmannibucau.wordpress.com> | Github < > >>> https://github.com/rmannibucau> | > >>>> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber > >>>> <http://www.tomitribe.com> > >>>> > >>>> 2016-02-16 8:13 GMT+01:00 Xavier Dury <[email protected]>: > >>>> > >>>>> Hi Romain, > >>>>> > >>>>> You can find my code at https://github.com/kalgon/jaxb-cdi-test > >>>>> > >>>>> I've stripped my extension down to the minimum (I removed the > scanning > >>> and > >>>>> I am just instantiating an empty JAXBContext). > >>>>> > >>>>> It seems that OWB wants to use the JAXBContext ClassLoader (which is > >>> null). > >>>>> > >>>>> The problem could also come from an incorrect use of the BeanBuilder > >>> (but > >>>>> that extension works well in wildfly, it only fails in my tests with > >>>>> OpenEJB). > >>>>> > >>>>> Thanks, > >>>>> > >>>>> Xavier > >>>>> > >>>>> ---------------------------------------- > >>>>>> From: [email protected] > >>>>>> Date: Mon, 15 Feb 2016 17:36:17 +0100 > >>>>>> Subject: Re: NPE when creating a bean through Extension and not > through > >>>>> Producer > >>>>>> To: [email protected] > >>>>>> > >>>>>> Hi Xavier, > >>>>>> > >>>>>> do you have some code to share - hope google didnt eat any snippet > >>> again? > >>>>>> > >>>>>> > >>>>>> Romain Manni-Bucau > >>>>>> @rmannibucau <https://twitter.com/rmannibucau> | Blog > >>>>>> <http://rmannibucau.wordpress.com> | Github < > >>>>> https://github.com/rmannibucau> | > >>>>>> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber > >>>>>> <http://www.tomitribe.com> > >>>>>> > >>>>>> 2016-02-15 16:47 GMT+01:00 Xavier Dury <[email protected]>: > >>>>>> > >>>>>>> Hi, > >>>>>>> > >>>>>>> I have written a CDI custom extension (with deltaspike > BeanBuilder) to > >>>>>>> scan all types annotated with @XmlRegistry and create one > >>>>>>> @ApplicationScoped JAXBContext for my application. > >>>>>>> > >>>>>>> But beans referencing/injecting that JAXBContext give a NPE when > >>>>> created: > >>>>>>> > >>>>>>> java.lang.NullPointerException > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.proxy.AbstractProxyFactory.defineAndLoadClass(AbstractProxyFactory.java:329) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.proxy.AbstractProxyFactory.createProxyClass(AbstractProxyFactory.java:240) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.proxy.AbstractProxyFactory.createProxyClass(AbstractProxyFactory.java:214) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.proxy.NormalScopeProxyFactory.createProxyClass(NormalScopeProxyFactory.java:269) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.proxy.NormalScopeProxyFactory.createProxyClass(NormalScopeProxyFactory.java:200) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.proxy.NormalScopeProxyFactory.createNormalScopeProxy(NormalScopeProxyFactory.java:149) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:767) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:668) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.inject.AbstractInjectable.inject(AbstractInjectable.java:103) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.inject.InjectableField.doInjection(InjectableField.java:65) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.portable.InjectionTargetImpl.injectFields(InjectionTargetImpl.java:220) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:206) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.webbeans.portable.InjectionTargetImpl.inject(InjectionTargetImpl.java:196) > >>>>>>> at > org.apache.webbeans.inject.OWBInjector.inject(OWBInjector.java:56) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.openejb.testing.ApplicationComposers.enrich(ApplicationComposers.java:949) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.openejb.testing.ApplicationComposers.deployApp(ApplicationComposers.java:729) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.openejb.testing.ApplicationComposers.before(ApplicationComposers.java:383) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.openejb.testing.ApplicationComposers.evaluate(ApplicationComposers.java:1060) > >>>>>>> at > >>>>>>> > >>>>> > >>> > org.apache.openejb.junit.DeployApplication.evaluate(DeployApplication.java:40) > >>>>>>> > >>>>>>> The weird part is that when I create a JAXBContext through a > >>> Producer, I > >>>>>>> don't have this error. > >>>>>>> > >>>>>>> I have written 2 test cases with ApplicationComposer (one which > >>> creates > >>>>>>> the JAXBContext through @Produces and the other through an > extension) > >>>>> but I > >>>>>>> don't know where to report this error as the problem seems to come > >>> from > >>>>>>> openwebbeans but I am using deltaspike and openejb to reproduce it. > >>>>>>> > >>>>>>> Hopefully, some people on this mailing list are members of the 3 > >>>>> projects > >>>>>>> ;-) > >>>>>>> > >>>>>>> Xavier > >>>>>>> > >>>>> > >>>>> > >>> > >>> > > > >
