From 832a7518febbee26c2cc63ee0a648b6606709c43 Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Mon, 3 Jul 2023 13:16:59 -0400 Subject: [PATCH] Modify WELD-1234 fix to avoid calling SessionObjectReference.isRemoved() on every invocation. --- .../ejb/EnterpriseBeanProxyMethodHandler.java | 17 +++++++++++------ .../tests/enterprise/weld1234/Weld1234Test.java | 6 ++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/modules/ejb/src/main/java/org/jboss/weld/module/ejb/EnterpriseBeanProxyMethodHandler.java b/modules/ejb/src/main/java/org/jboss/weld/module/ejb/EnterpriseBeanProxyMethodHandler.java index bd184e5ae0d..954c9f36351 100644 --- a/modules/ejb/src/main/java/org/jboss/weld/module/ejb/EnterpriseBeanProxyMethodHandler.java +++ b/modules/ejb/src/main/java/org/jboss/weld/module/ejb/EnterpriseBeanProxyMethodHandler.java @@ -25,6 +25,7 @@ import java.util.Set; import jakarta.ejb.EJBException; +import jakarta.ejb.NoSuchEJBException; import org.jboss.weld.annotated.enhanced.MethodSignature; import org.jboss.weld.annotated.enhanced.jlr.MethodSignatureImpl; @@ -123,17 +124,21 @@ public Object invoke(Object self, Method method, Method proceed, Object[] args) throw BeanLogger.LOG.invalidRemoveMethodInvocation(method); } Class businessInterface = getBusinessInterface(method); - if (reference.isRemoved() && isToStringMethod(method)) { - return businessInterface.getName() + " [REMOVED]"; - } Object proxiedInstance = reference.getBusinessObject(businessInterface); if (!Modifier.isPublic(method.getModifiers())) { throw new EJBException("Not a business method " + method.toString() +". Do not call non-public methods on EJB's."); } - Object returnValue = Reflections.invokeAndUnwrap(proxiedInstance, method, args); - BeanLogger.LOG.callProxiedMethod(method, proxiedInstance, args, returnValue); - return returnValue; + try { + Object returnValue = Reflections.invokeAndUnwrap(proxiedInstance, method, args); + BeanLogger.LOG.callProxiedMethod(method, proxiedInstance, args, returnValue); + return returnValue; + } catch (NoSuchEJBException e) { + if (isToStringMethod(method)) { + return businessInterface.getName() + " [REMOVED]"; + } + throw e; + } } private boolean isRemoveMethod(Method method) { diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/enterprise/weld1234/Weld1234Test.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/enterprise/weld1234/Weld1234Test.java index 684d11f7103..657e867a9b0 100644 --- a/tests-arquillian/src/test/java/org/jboss/weld/tests/enterprise/weld1234/Weld1234Test.java +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/enterprise/weld1234/Weld1234Test.java @@ -31,7 +31,6 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -57,9 +56,8 @@ public void testRemovedEjbToString() { } catch (Exception e) { } - // check if toString() still works - String toString = exceptionGenerator.toString(); - assertTrue(toString.contains("REMOVED")); + // Verify that toString() still works + exceptionGenerator.toString(); try { // check if other methods throw NoSuchEJBException