Bug 104738

Summary: [1.5][compiler] Enclosing method attribute is generated for member type of a local type
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: philippe_mulet
Version: 3.1   
Target Milestone: 3.1.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Regression test none

Description Olivier Thomann CLA 2005-07-21 17:31:00 EDT
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().
Comment 1 Olivier Thomann CLA 2005-07-21 17:33:00 EDT
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.
Comment 2 Olivier Thomann CLA 2005-07-21 17:39:22 EDT
Created attachment 25162 [details]
Proposed fix
Comment 3 Philipe Mulet CLA 2005-07-22 09:52:09 EDT
+1
Comment 4 Olivier Thomann CLA 2005-07-25 10:42:13 EDT
Fixed and released in HEAD.
Regression test added in
org.eclipse.jdt.core.tests.compiler.regression.EnclosingMethodAttributeTest.test001
Comment 5 Olivier Thomann CLA 2005-07-25 10:46:10 EDT
Created attachment 25243 [details]
Regression test
Comment 6 Olivier Thomann CLA 2005-07-25 10:51:52 EDT
New regression test
org.eclipse.jdt.core.tests.compiler.regression.EnclosingMethodAttributeTest.test002
Comment 7 Olivier Thomann CLA 2005-07-25 11:10:03 EDT
Backported to 3.1 maintenance stream.
Comment 8 Jerome Lanneluc CLA 2005-08-11 10:24:49 EDT
Verified with 3.2 M1
Comment 9 Maxime Daniel CLA 2005-09-21 09:11:54 EDT
Verified for 3.2 M2 with build I20050920-0010.
Comment 10 David Audel CLA 2005-09-26 12:36:06 EDT
Verified using M20050923-1430 for 3.1.1