[ https://issues.apache.org/jira/browse/OPENEJB-2009?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13610262#comment-13610262 ]
Xavier Dury commented on OPENEJB-2009: -------------------------------------- Do you swallow the exception or did you change the log statement in the catch? My main concern was that: logger.log(Level.FINE, "The stateful instance " + instance + " can't be removed since it was invalidated", e); will never succeed because if the instance is indeed invalidated, constructing the log message will call instance.toString(), the former statement can be rewritten; logger.log(Level.FINE, "The stateful instance " + instance.toString() + " can't be removed since it was invalidated", e); as toString() will throw a NoSuchEJBException, this log is useless. So you could either: 1) just call instance.hashCode() and remove the (useless) try/catch block around it and swallow the exception higher 2) or change the log message by removing the "..." + instance + "..." in it. Concerning the equals problem: In the snapshot version I have today, CdiPlugin.InstanceBean.equals(Object o) is defined as "return this == o || bean == o;" I have the following scenario: InstanceBean1 != InstanceBean2 (2 different instances) InstanceBean1.bean == InstanceBean2.bean As per the definition of InstanceBean.equals(), InstanceBean1.equals(InstanceBean2) will always return false because (this == o) == false because InstanceBean1 != InstanceBean2 (as stated before) (bean == o) == false because InstanceBean1.bean (CdiEjbBean) != InstanceBean2 (InstanceBean) I think the InstanceBean.equals() should be changed to something like "return this == o || o != null && o.equals(this.bean)" > 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 > Attachments: openejb-2009.zip > > > 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