Summary
The EnclosingMethod
attribute of anonymous or local inner classes declared inside a lambda is not pointing to the method that enclosed the original declaration, which should be considered as the closest lexically enclosing method.
Problem
If an anonymous or local inner class is declared inside of a lambda, the EnclosingMethod
attribute on that class refers to the synthetic lambda method rather than the method that enclosed the original declaration. The original method should be considered as the closest lexically enclosing method.
Solution
Point the EnclosingMethod
attribute of inner classes declared inside a lambda to the original enclosing method. There is no need to change anything in the JLS but the compiler should be updated so that the EnclosingMethod
attribute of anonymous or local inner classes declared inside a lambda point to the method enclosing the declaration.
Specification
JVMS 11 4.7.7: It is the responsibility of a Java compiler to ensure that the method identified via the method_index is indeed the closest lexically enclosing method of the class that contains this EnclosingMethod attribute.
A synthetic method as the one that is generated for lambdas shouldn't be considered as the closest lexically enclosing method.
- csr of
-
JDK-8215470 Bad EnclosingMethod attribute on classes declared in lambdas
-
- Resolved
-