Bug 104738 - [1.5][compiler] Enclosing method attribute is generated for member type of a local type
Summary: [1.5][compiler] Enclosing method attribute is generated for member type of a ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-21 17:31 EDT by Olivier Thomann CLA
Modified: 2005-09-26 12:36 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix (905 bytes, patch)
2005-07-21 17:39 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression test (4.84 KB, patch)
2005-07-25 10:46 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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