You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Xavier Dury <ka...@hotmail.com> on 2016/02/15 16:47:37 UTC

NPE when creating a bean through Extension and not through Producer

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
 		 	   		  

Re: NPE when creating a bean through Extension and not through Producer

Posted by Romain Manni-Bucau <rm...@gmail.com>.
2016-02-16 11:10 GMT+01:00 Xavier Dury <ka...@hotmail.com>:

> I tried META-INF/application.properties, @Configuration,
> @ContainerProperties but my ApplicationBoundaryService is never picked up
> in my tests so I bumped OWB's version to 1.6.3-SNAPSHOT and my tests are
> now passing.
>
>
yep fixed it for M2 for 4 or 5 service types


> Hope 1.6.3 will be released for TomEE M2! (Would you risk giving a release
> date by any chance? ;-)
>
>
should be this week for OWB, M2 will follow hopefully this month


> Anyway, thanks for the support!
>
> ----------------------------------------
> > From: rmannibucau@gmail.com
> > Date: Tue, 16 Feb 2016 10:00:53 +0100
> > Subject: Re: NPE when creating a bean through Extension and not through
> Producer
> > To: users@tomee.apache.org
> >
> > few are no more accessible - will check them for the coming M2. TomEE
> uses
> > application.properties and not openwebbeans.properties.
> >
> >
> > 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:56 GMT+01:00 Xavier Dury <ka...@hotmail.com>:
> >
> >> Thanks,
> >>
> >> I was trying to implement a custom ApplicationBoundaryService but OWB
> does
> >> not seem to pick it up (I added the class name to
> >> META-INF/openwebbeans/openwebbeans.properties with a
> configuration.ordinal
> >> over 9000 but it always takes the default one).
> >>
> >> Are those OWB SPIs required to be in a jar or something?
> >>
> >> ----------------------------------------
> >>> From: rmannibucau@gmail.com
> >>> Date: Tue, 16 Feb 2016 09:42:14 +0100
> >>> Subject: Re: NPE when creating a bean through Extension and not through
> >> Producer
> >>> To: users@tomee.apache.org
> >>>
> >>> FYI: Mark already enhanced app boundary service for ​1.6.3 release and
> it
> >>> fixes your issue
> >>
> >>
>
>

RE: NPE when creating a bean through Extension and not through Producer

Posted by Xavier Dury <ka...@hotmail.com>.
I tried META-INF/application.properties, @Configuration, @ContainerProperties but my ApplicationBoundaryService is never picked up in my tests so I bumped OWB's version to 1.6.3-SNAPSHOT and my tests are now passing.

Hope 1.6.3 will be released for TomEE M2! (Would you risk giving a release date by any chance? ;-)

Anyway, thanks for the support!

----------------------------------------
> From: rmannibucau@gmail.com
> Date: Tue, 16 Feb 2016 10:00:53 +0100
> Subject: Re: NPE when creating a bean through Extension and not through Producer
> To: users@tomee.apache.org
>
> few are no more accessible - will check them for the coming M2. TomEE uses
> application.properties and not openwebbeans.properties.
>
>
> 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:56 GMT+01:00 Xavier Dury <ka...@hotmail.com>:
>
>> Thanks,
>>
>> I was trying to implement a custom ApplicationBoundaryService but OWB does
>> not seem to pick it up (I added the class name to
>> META-INF/openwebbeans/openwebbeans.properties with a configuration.ordinal
>> over 9000 but it always takes the default one).
>>
>> Are those OWB SPIs required to be in a jar or something?
>>
>> ----------------------------------------
>>> From: rmannibucau@gmail.com
>>> Date: Tue, 16 Feb 2016 09:42:14 +0100
>>> Subject: Re: NPE when creating a bean through Extension and not through
>> Producer
>>> To: users@tomee.apache.org
>>>
>>> FYI: Mark already enhanced app boundary service for ​1.6.3 release and it
>>> fixes your issue
>>
>>
 		 	   		  

Re: NPE when creating a bean through Extension and not through Producer

Posted by Romain Manni-Bucau <rm...@gmail.com>.
few are no more accessible - will check them for the coming M2. TomEE uses
application.properties and not openwebbeans.properties.


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:56 GMT+01:00 Xavier Dury <ka...@hotmail.com>:

> Thanks,
>
> I was trying to implement a custom ApplicationBoundaryService but OWB does
> not seem to pick it up (I added the class name to
> META-INF/openwebbeans/openwebbeans.properties with a configuration.ordinal
> over 9000 but it always takes the default one).
>
> Are those OWB SPIs required to be in a jar or something?
>
> ----------------------------------------
> > From: rmannibucau@gmail.com
> > Date: Tue, 16 Feb 2016 09:42:14 +0100
> > Subject: Re: NPE when creating a bean through Extension and not through
> Producer
> > To: users@tomee.apache.org
> >
> > FYI: Mark already enhanced app boundary service for ​1.6.3 release and it
> > fixes your issue
>
>

RE: NPE when creating a bean through Extension and not through Producer

Posted by Xavier Dury <ka...@hotmail.com>.
Thanks,

I was trying to implement a custom ApplicationBoundaryService but OWB does not seem to pick it up (I added the class name to META-INF/openwebbeans/openwebbeans.properties with a configuration.ordinal over 9000 but it always takes the default one).

Are those OWB SPIs required to be in a jar or something?

----------------------------------------
> From: rmannibucau@gmail.com
> Date: Tue, 16 Feb 2016 09:42:14 +0100
> Subject: Re: NPE when creating a bean through Extension and not through Producer
> To: users@tomee.apache.org
>
> FYI: Mark already enhanced app boundary service for ​1.6.3 release and it
> fixes your issue
 		 	   		  

Re: NPE when creating a bean through Extension and not through Producer

Posted by Romain Manni-Bucau <rm...@gmail.com>.
FYI: Mark already enhanced app boundary service for ​1.6.3 release and it
fixes your issue

Re: NPE when creating a bean through Extension and not through Producer

Posted by Romain Manni-Bucau <rm...@gmail.com>.
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 <ka...@hotmail.com>:

> 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: kalgon@hotmail.com
> > To: users@tomee.apache.org
> > 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: rmannibucau@gmail.com
> >> Date: Tue, 16 Feb 2016 08:44:31 +0100
> >> Subject: Re: NPE when creating a bean through Extension and not through
> Producer
> >> To: users@tomee.apache.org
> >>
> >> 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 <ka...@hotmail.com>:
> >>
> >>> 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: rmannibucau@gmail.com
> >>>> Date: Tue, 16 Feb 2016 08:25:06 +0100
> >>>> Subject: Re: NPE when creating a bean through Extension and not
> through
> >>> Producer
> >>>> To: users@tomee.apache.org
> >>>>
> >>>> 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 <ka...@hotmail.com>:
> >>>>
> >>>>> 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: rmannibucau@gmail.com
> >>>>>> Date: Mon, 15 Feb 2016 17:36:17 +0100
> >>>>>> Subject: Re: NPE when creating a bean through Extension and not
> through
> >>>>> Producer
> >>>>>> To: users@tomee.apache.org
> >>>>>>
> >>>>>> 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 <ka...@hotmail.com>:
> >>>>>>
> >>>>>>> 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
> >>>>>>>
> >>>>>
> >>>>>
> >>>
> >>>
> >
>
>

RE: NPE when creating a bean through Extension and not through Producer

Posted by Xavier Dury <ka...@hotmail.com>.
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: kalgon@hotmail.com
> To: users@tomee.apache.org
> 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: rmannibucau@gmail.com
>> Date: Tue, 16 Feb 2016 08:44:31 +0100
>> Subject: Re: NPE when creating a bean through Extension and not through Producer
>> To: users@tomee.apache.org
>>
>> 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 <ka...@hotmail.com>:
>>
>>> 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: rmannibucau@gmail.com
>>>> Date: Tue, 16 Feb 2016 08:25:06 +0100
>>>> Subject: Re: NPE when creating a bean through Extension and not through
>>> Producer
>>>> To: users@tomee.apache.org
>>>>
>>>> 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 <ka...@hotmail.com>:
>>>>
>>>>> 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: rmannibucau@gmail.com
>>>>>> Date: Mon, 15 Feb 2016 17:36:17 +0100
>>>>>> Subject: Re: NPE when creating a bean through Extension and not through
>>>>> Producer
>>>>>> To: users@tomee.apache.org
>>>>>>
>>>>>> 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 <ka...@hotmail.com>:
>>>>>>
>>>>>>> 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
>>>>>>>
>>>>>
>>>>>
>>>
>>>
>
 		 	   		  

RE: NPE when creating a bean through Extension and not through Producer

Posted by Xavier Dury <ka...@hotmail.com>.
Ok, thanks for the clarification!

----------------------------------------
> From: rmannibucau@gmail.com
> Date: Tue, 16 Feb 2016 08:44:31 +0100
> Subject: Re: NPE when creating a bean through Extension and not through Producer
> To: users@tomee.apache.org
>
> 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 <ka...@hotmail.com>:
>
>> 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: rmannibucau@gmail.com
>>> Date: Tue, 16 Feb 2016 08:25:06 +0100
>>> Subject: Re: NPE when creating a bean through Extension and not through
>> Producer
>>> To: users@tomee.apache.org
>>>
>>> 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 <ka...@hotmail.com>:
>>>
>>>> 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: rmannibucau@gmail.com
>>>>> Date: Mon, 15 Feb 2016 17:36:17 +0100
>>>>> Subject: Re: NPE when creating a bean through Extension and not through
>>>> Producer
>>>>> To: users@tomee.apache.org
>>>>>
>>>>> 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 <ka...@hotmail.com>:
>>>>>
>>>>>> 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
>>>>>>
>>>>
>>>>
>>
>>
 		 	   		  

Re: NPE when creating a bean through Extension and not through Producer

Posted by Romain Manni-Bucau <rm...@gmail.com>.
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 <ka...@hotmail.com>:

> 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: rmannibucau@gmail.com
> > Date: Tue, 16 Feb 2016 08:25:06 +0100
> > Subject: Re: NPE when creating a bean through Extension and not through
> Producer
> > To: users@tomee.apache.org
> >
> > 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 <ka...@hotmail.com>:
> >
> >> 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: rmannibucau@gmail.com
> >>> Date: Mon, 15 Feb 2016 17:36:17 +0100
> >>> Subject: Re: NPE when creating a bean through Extension and not through
> >> Producer
> >>> To: users@tomee.apache.org
> >>>
> >>> 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 <ka...@hotmail.com>:
> >>>
> >>>> 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
> >>>>
> >>
> >>
>
>

RE: NPE when creating a bean through Extension and not through Producer

Posted by Xavier Dury <ka...@hotmail.com>.
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: rmannibucau@gmail.com
> Date: Tue, 16 Feb 2016 08:25:06 +0100
> Subject: Re: NPE when creating a bean through Extension and not through Producer
> To: users@tomee.apache.org
>
> 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 <ka...@hotmail.com>:
>
>> 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: rmannibucau@gmail.com
>>> Date: Mon, 15 Feb 2016 17:36:17 +0100
>>> Subject: Re: NPE when creating a bean through Extension and not through
>> Producer
>>> To: users@tomee.apache.org
>>>
>>> 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 <ka...@hotmail.com>:
>>>
>>>> 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
>>>>
>>
>>
 		 	   		  

Re: NPE when creating a bean through Extension and not through Producer

Posted by Romain Manni-Bucau <rm...@gmail.com>.
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 <ka...@hotmail.com>:

> 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: rmannibucau@gmail.com
> > Date: Mon, 15 Feb 2016 17:36:17 +0100
> > Subject: Re: NPE when creating a bean through Extension and not through
> Producer
> > To: users@tomee.apache.org
> >
> > 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 <ka...@hotmail.com>:
> >
> >> 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
> >>
>
>

RE: NPE when creating a bean through Extension and not through Producer

Posted by Xavier Dury <ka...@hotmail.com>.
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: rmannibucau@gmail.com
> Date: Mon, 15 Feb 2016 17:36:17 +0100
> Subject: Re: NPE when creating a bean through Extension and not through Producer
> To: users@tomee.apache.org
>
> 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 <ka...@hotmail.com>:
>
>> 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
>>
 		 	   		  

Re: NPE when creating a bean through Extension and not through Producer

Posted by Romain Manni-Bucau <rm...@gmail.com>.
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 <ka...@hotmail.com>:

> 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
>