Bug 287009 - Inner Annotation Checks are Missing
Summary: Inner Annotation Checks are Missing
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: All Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.6 M2   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-19 01:03 EDT by Mahmood Ali CLA
Modified: 2010-03-01 14:25 EST (History)
3 users (show)

See Also:
kent_johnson: review+


Attachments
Proposed fix + regression test (2.36 KB, patch)
2009-08-26 05:03 EDT, Ayushman Jain CLA
no flags Details | Diff
Modified patch + regression test (2.31 KB, patch)
2009-08-27 05:18 EDT, Ayushman Jain CLA
Olivier_Thomann: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mahmood Ali CLA 2009-08-19 01:03:13 EDT
Build ID: M20090211-1700

Steps To Reproduce:
1. Create a Java Project.
2. Create a new Java source file Test.java with the following content:

    @interface Anno { Anno value(); }

Expected behavior: You would get an error: 'Cycle detected: the annotation Anno cannot contain attributes of the annotation type itself

3. Wrap the annotation within a test class, as in
class Test {
    @interface Anno { Anno value(); }
}

Expected Behavior: You sill get the same error

4. Modify Test class to be generic:
class Test<T> {
    @interface Anno { Anno value(); }
}

Expected behavior: The error is still issued
Actual behavior: error is not emitted in the last case.

Sun's javac reports the expected error in all cases.

More information:
It seems that some annotation type checks are missing if the annotation declaration is an inner class of a generic class.
Comment 1 Olivier Thomann CLA 2009-08-19 07:58:42 EDT
Ayushman, please investigate.
Comment 2 Ayushman Jain CLA 2009-08-25 09:01:57 EDT
The problem is in ReferenceBinding$detectAnnotationCycle . In the non generic class case, the signature of method value is 'Test.Anno value()', while in the generic case, signature is simply 'Anno value'. So in the latter case the comparison of return type of method value with the member type Anno fails. Hence no cycle is reported. Fixing the problem results in the following error for the generic class case.

Cycle detected: a cycle exists between annotation attributes of Test<T>.Anno and Test.Anno
 whereas it should actually be 
Cycle detected: the annotation Anno cannot contain attributes of the annotation type itself

(i think this happens because of type erasure.I'm not sure though.)

Also, I'm not sure whether the signature for the generic case is correct. Shouldn't it also be Test.Anno value()? Kent, what do you think?  
Comment 3 Kent Johnson CLA 2009-08-25 12:23:06 EDT
> Also, I'm not sure whether the signature for the generic case is correct.
> Shouldn't it also be Test.Anno value()?

Do you mean in the error message ? If so, then no it should be "Test<T>.Anno"


I got the 'correct' error message with a simple change :

Cycle detected: the annotation Test<T>.Anno cannot contain attributes of the annotation type itself


Hint : the return type needs to be converted.
Comment 4 Ayushman Jain CLA 2009-08-26 05:03:12 EDT
Created attachment 145638 [details]
Proposed fix + regression test

Thanx Kent. So basically the problem was indeed due to type erasure.
Comment 5 Kent Johnson CLA 2009-08-26 09:53:57 EDT
I would have done this instead :

TypeBinding returnType = currentMethods[i].returnType.leafComponentType().erasure();

We do not need the parameterized return type so just convert it.
Comment 6 Olivier Thomann CLA 2009-08-26 12:17:01 EDT
Ayushman, please provide a new patch based on Kent's comment.
Once this is done, Kent, please review and release.
Comment 7 Ayushman Jain CLA 2009-08-27 05:18:00 EDT
Created attachment 145767 [details]
Modified patch + regression test
Comment 8 Kent Johnson CLA 2009-08-27 10:17:07 EDT
Released to HEAD for 3.6M2
Comment 9 Satyam Kandula CLA 2009-09-15 04:07:56 EDT
Verified for 3.6M2 using I20090914-1800 build
Comment 10 Olivier Thomann CLA 2009-09-15 16:00:06 EDT
Verified.