Community
Participate
Working Groups
In case a member type is within a local class, it should not get an enclosing method attribute. public class Test { public static void main(String[] args) throws Exception { class MyLocal$A { class Member { } }; System.out.println(MyLocal$A.Member.class.getEnclosingMethod()); System.out.println(MyLocal$A.Member.class.getEnclosingConstructor()); } } At runtime we get: Exception in thread "main" java.lang.InternalError: Enclosing method not found at java.lang.Class.getEnclosingMethod(Class.java:916) at X.main(X.java:7) We should check for isNestedType() && !isMemberType() to find out if we should add an enclosing method attribute instead of checking isAnonymous() || isLocalType().
Philippe, I think this should be a candidate for 3.1.1. The fix is trivial and without it we can blow up at runtime.
Created attachment 25162 [details] Proposed fix
+1
Fixed and released in HEAD. Regression test added in org.eclipse.jdt.core.tests.compiler.regression.EnclosingMethodAttributeTest.test001
Created attachment 25243 [details] Regression test
New regression test org.eclipse.jdt.core.tests.compiler.regression.EnclosingMethodAttributeTest.test002
Backported to 3.1 maintenance stream.
Verified with 3.2 M1
Verified for 3.2 M2 with build I20050920-0010.
Verified using M20050923-1430 for 3.1.1