Xavier Dury created OPENEJB-2009:
------------------------------------

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