Skip to content

Commit 21fcc0f

Browse files
committed
WELD-2806 Prevent compiled lambdas in class from being processed as interceptable methods.
1 parent 4e71b88 commit 21fcc0f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

impl/src/main/java/org/jboss/weld/util/Beans.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.lang.annotation.Annotation;
2121
import java.lang.annotation.Repeatable;
2222
import java.lang.reflect.GenericArrayType;
23+
import java.lang.reflect.Method;
2324
import java.lang.reflect.Modifier;
2425
import java.lang.reflect.ParameterizedType;
2526
import java.lang.reflect.Type;
@@ -169,7 +170,7 @@ public static boolean isBeanProxyable(Bean<?> bean, BeanManagerImpl manager) {
169170
// note that a bridge method can be a candidate for interception in rare cases; do not discard those
170171
boolean businessMethod = !annotatedMethod.isStatic() && !annotatedMethod.isAnnotationPresent(Inject.class);
171172

172-
if (businessMethod && !isInterceptorMethod(annotatedMethod)) {
173+
if (businessMethod && !isInterceptorMethod(annotatedMethod) && !isLambdaMethod(annotatedMethod)) {
173174
annotatedMethods.add(annotatedMethod);
174175
}
175176
}
@@ -185,6 +186,14 @@ private static boolean isInterceptorMethod(AnnotatedMethod<?> annotatedMethod) {
185186
return false;
186187
}
187188

189+
// Lambdas in classes will be compiled into methods declared on that given class.
190+
// The exact representation differs between javac (standard compiler) and EJC (Eclipse compiler).
191+
// We want to avoid attempting to intercept these methods - note that the detection is on a "best effort" basis.
192+
private static boolean isLambdaMethod(AnnotatedMethod<?> annotatedMethod) {
193+
Method javaMember = annotatedMethod.getJavaMember();
194+
return !javaMember.isBridge() && javaMember.isSynthetic();
195+
}
196+
188197
/**
189198
* Checks that all the qualifiers in the set requiredQualifiers are in the set of qualifiers. Qualifier equality rules for
190199
* annotation members are followed.

0 commit comments

Comments
 (0)