[ 
https://issues.apache.org/jira/browse/OPENEJB-2009?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13609023#comment-13609023
 ] 

Xavier Dury commented on OPENEJB-2009:
--------------------------------------

I tried with OpenEJB 4.5.2-SNAPSHOT but I didn't go so far. I have a Stateful 
bean which belongs to a CDI custom scope. It seems that with 4.5.1, the bean 
can be retrieved from my scope without problem (it's correctly propagated). In 
4.5.2-SNAPSHOT, my bean is created twice and is not correctly initialized, 
throwing an exception earlier.

But from what I can see in 4.5.2-SNAPSHOT source code, 
CdiEjbBean.destroyScopedStateful() has not changed.
                
> Bug in CdiEjbBean
> -----------------
>
>                 Key: OPENEJB-2009
>                 URL: https://issues.apache.org/jira/browse/OPENEJB-2009
>             Project: OpenEJB
>          Issue Type: Bug
>          Components: general
>    Affects Versions: 4.5.1
>            Reporter: Xavier Dury
>
> In CdiEjbBean.destroyScopedStateful(), a test is made to check if a stateful 
> bean is invalidated (by calling instance.hashcode and getting a 
> NoSuchEjbException). The problem is that if the bean is actually invalidated, 
> it's logged and instance.toString() will be called and this will throw a 
> NoSuchEjbException outside of the try/catch.
> {{
> private void destroyScopedStateful(final T instance, final 
> CreationalContext<T> cc) {
>   try {
>     instance.hashCode(); // force the instance to be created - otherwise 
> we'll miss @PreDestroy for instance
>   } catch (NoSuchEJBException e) {
>     logger.log(Level.FINE, "The stateful instance " + instance + " can't be 
> removed since it was invalidated", e);
>     return;
>   }
>   ...
> }
> }}
> error:
> {{
> ERROR 14:56:13 [main] org.apache.openejb.cdi.CdiEjbBean - Exception thrown 
> while destroying bean instance : [MyStatefulBean, Name:null, WebBeans 
> Type:ENTERPRISE, API Types:[java.lang.Object,test.MyStateful], 
> Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]]
> javax.ejb.NoSuchEJBException: reference is invalid for MyStatefulBean
>       at 
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.isValidReference(BaseEjbProxyHandler.java:314)
>       at 
> org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:219)
>       at $Proxy138.toString(Unknown Source)
>       at java.lang.String.valueOf(String.java:2826)
>       at java.lang.StringBuilder.append(StringBuilder.java:115)
>       at 
> org.apache.openejb.cdi.CdiEjbBean.destroyScopedStateful(CdiEjbBean.java:369)
>       at 
> org.apache.openejb.cdi.CdiEjbBean.destroyComponentInstance(CdiEjbBean.java:241)
>       at 
> org.apache.webbeans.component.AbstractInjectionTargetBean.destroyInstance(AbstractInjectionTargetBean.java:176)
>       at 
> org.apache.webbeans.component.AbstractOwbBean.destroyCreatedInstance(AbstractOwbBean.java:287)
>       at 
> org.apache.webbeans.portable.creation.InjectionTargetProducer.preDestroy(InjectionTargetProducer.java:132)
>       at 
> org.apache.webbeans.component.InjectionTargetWrapper.preDestroy(InjectionTargetWrapper.java:98)
>       at 
> org.apache.webbeans.component.AbstractOwbBean.destroy(AbstractOwbBean.java:251)
>       at 
> org.apache.openejb.cdi.CdiEjbBean$InstanceBean.destroy(CdiEjbBean.java:461)
> }}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to