Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 342470

Summary: javax.lang.model.element.Element.getEnclosingElement() doesn't return null for type parameter
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: APTAssignee: Olivier Thomann <Olivier_Thomann>
Status: RESOLVED FIXED QA Contact:
Severity: trivial    
Priority: P3 CC: eclipse
Version: 3.7   
Target Milestone: 3.7 M7   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Proposed fix + regression test
none
Proposed fix + regression test
none
Proposed fix + regression test none

Description Olivier Thomann CLA 2011-04-11 12:49:36 EDT
The method javadoc has been changed between 1.6 and 1.7 to no longer return null for type parameter.
See http://download.java.net/jdk7/docs/api/javax/lang/model/element/Element.html#getEnclosingElement()

vs:

http://download.oracle.com/javase/6/docs/api/javax/lang/model/element/Element.html#getEnclosingElement()

Checking with javac 1.6, it looks like the System compiler never returned null. So we should also fix our implementation to make sure we match the new documentation.
I don't think we should fix it according to the target source version of the annotation processor. We should simply return the getGenericElement() value in this case.
Comment 1 Olivier Thomann CLA 2011-04-11 12:51:33 EDT
Created attachment 192946 [details]
Proposed fix + regression test

Walter, I would take care of releasing this.
Are you ok with that change ?
Comment 2 Olivier Thomann CLA 2011-04-11 12:53:29 EDT
Created attachment 192947 [details]
Proposed fix + regression test

Same patch with updated copyrights.
Comment 3 Olivier Thomann CLA 2011-04-11 12:58:36 EDT
Created attachment 192948 [details]
Proposed fix + regression test

Improved regression test to check that the getEnclosingElement() is equals to the getGenericElement() for type parameter instead of just checking it is not null.
Comment 4 Walter Harley CLA 2011-04-11 13:21:25 EDT
Sounds like a typical case of Sun changing the spec to match their implementation, rather than changing the implementation to match the spec.

I checked the Sun bug database but I don't see any commentary on this.  I think it is okay to change the behavior for 3.7 given that javac 1.6 works this way.
Comment 5 Olivier Thomann CLA 2011-04-11 16:52:13 EDT
Released for 3.7M7.