Bug 191082

Summary: AnnotationMirror.getPosition() returns wrong value
Product: [Eclipse Project] JDT Reporter: Kenneth Cheung <kennethc>
Component: APTAssignee: Olivier Thomann <Olivier_Thomann>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: eclipse, jpitman, philippe_mulet
Version: 3.3   
Target Milestone: 3.3.1   
Hardware: PC   
OS: All   
Whiteboard:
Bug Depends on: 192774    
Bug Blocks:    
Attachments:
Description Flags
Regression tests none

Description Kenneth Cheung CLA 2007-06-05 13:25:19 EDT
If I have multiple annotation mirrors that looks exactly the same, the AnnotationMirror.getPosition() just returns the position of one of them.  (Usually the last one.)

For example in the following Java file:
package myTests;

import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;

public class TestMultipleAroundInvoke {
@AroundInvoke() public Object foo(InvocationContext ic) throws Exception {
	return null;
}
@AroundInvoke() public Object foo2(InvocationContext ic) throws Exception {
	return null;
}
@AroundInvoke() public Object foo3(InvocationContext ic) throws Exception {
	return null;
}
}



Collection<AnnotationMirror> mirrors = decl.getAnnotationMirrors();
for (AnnotationMirror mirror : mirrors) {
    System.out.println("[" + declaration + ", " + mirror + "@" + mirror.getPosition);() + "]"
}

will produce output like:
[Object foo(InvocationContext ic), @AroundInvoke()@offset = 326 line = 13 column = 1 length = 12]
[Object foo2(InvocationContext ic), @AroundInvoke()@offset = 326 line = 13 column = 1 length = 12]
[Object foo3(InvocationContext ic), @AroundInvoke()@offset = 326 line = 13 column = 1 length = 12]

Thanks.
Comment 1 Walter Harley CLA 2007-06-11 20:04:56 EDT
I am able to reproduce this.  The position returned by the annotated declaration is correct, but the position returned by the annotation mirror itself is not.  Am investigating.
Comment 2 Walter Harley CLA 2007-06-13 20:12:56 EDT
This looks like a JDT Core 3.3 regression.  In 3.3, cacheing and reuse of compiler internal annotation bindings was introduced (changes introduced in LookupEnvironment version 1.82 and 1.83), but DefaultBindingResolver.getAnnotationInstance() is supposed to be able to translate from a compiler internal annotation binding to a DOM IAnnotationBinding.  Reuse means there is not a 1:1 relationship any more so this translation is broken.

I will spawn a JDT Core bug for this, and leave this bug open to create a test case for APT.
Comment 3 Olivier Thomann CLA 2007-06-15 10:50:36 EDT
This is indeed broken. We need to either not have unique compiler annotation bindings or change the binding resolver to be able to retrieve the right ast node when an annotation binding is found.
I am investigating.
Sounds like a must have for 3.3.1.
Comment 4 Walter Harley CLA 2007-06-15 12:52:49 EDT
I agree with both the analysis and the prioritization.  Thanks, Olivier.
Comment 5 Olivier Thomann CLA 2007-07-04 14:52:56 EDT
Created attachment 73056 [details]
Regression tests
Comment 6 Olivier Thomann CLA 2007-07-05 09:42:55 EDT
Set target as 3.3.1 since this is related to bug 192774 which is targetted for 3.3.1.
Comment 7 Olivier Thomann CLA 2007-07-05 09:48:51 EDT
Released for 3.3.1.
Same regression tests as bug 192774.
Comment 8 Olivier Thomann CLA 2007-07-05 09:54:13 EDT
Released for 3.4M1.
Same regression tests as branch 3.3.1.