Community
Participate
Working Groups
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.
Ayushman, please investigate.
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?
> 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.
Created attachment 145638 [details] Proposed fix + regression test Thanx Kent. So basically the problem was indeed due to type erasure.
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.
Ayushman, please provide a new patch based on Kent's comment. Once this is done, Kent, please review and release.
Created attachment 145767 [details] Modified patch + regression test
Released to HEAD for 3.6M2
Verified for 3.6M2 using I20090914-1800 build
Verified.