Skip to content

Commit

Permalink
WELD-2806 Prevent compiled lambdas in class from being processed as i…
Browse files Browse the repository at this point in the history
…nterceptable methods.
  • Loading branch information
manovotn committed Jan 15, 2025
1 parent 4e71b88 commit 21fcc0f
Showing 1 changed file with 10 additions and 1 deletion.
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

0 comments on commit 21fcc0f

Please sign in to comment.