Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WELD-2747 Avoid calling SessionObjectReference.isRemoved() on every invocation. #2862

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand Down
Loading