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-2806 Prevent compiled lambdas in class from being processed as interceptable methods. #3110

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
11 changes: 10 additions & 1 deletion impl/src/main/java/org/jboss/weld/util/Beans.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.Repeatable;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -169,7 +170,7 @@ public static boolean isBeanProxyable(Bean<?> bean, BeanManagerImpl manager) {
// note that a bridge method can be a candidate for interception in rare cases; do not discard those
boolean businessMethod = !annotatedMethod.isStatic() && !annotatedMethod.isAnnotationPresent(Inject.class);

if (businessMethod && !isInterceptorMethod(annotatedMethod)) {
if (businessMethod && !isInterceptorMethod(annotatedMethod) && !isLambdaMethod(annotatedMethod)) {
annotatedMethods.add(annotatedMethod);
}
}
Expand All @@ -185,6 +186,14 @@ private static boolean isInterceptorMethod(AnnotatedMethod<?> annotatedMethod) {
return false;
}

// Lambdas in classes will be compiled into methods declared on that given class.
// The exact representation differs between javac (standard compiler) and EJC (Eclipse compiler).
// We want to avoid attempting to intercept these methods - note that the detection is on a "best effort" basis.
private static boolean isLambdaMethod(AnnotatedMethod<?> annotatedMethod) {
Method javaMember = annotatedMethod.getJavaMember();
return !javaMember.isBridge() && javaMember.isSynthetic();
}

/**
* Checks that all the qualifiers in the set requiredQualifiers are in the set of qualifiers. Qualifier equality rules for
* annotation members are followed.
Expand Down
Loading