JDK-8005681 : Repeated annotations on new,array,cast are not written to class file
Type:Bug
Component:tools
Sub-Component:javac
Affected Version:8
Priority:P3
Status:Closed
Resolution:Fixed
Submitted:2013-01-03
Updated:2014-02-06
Resolved:2013-05-15
The Version table provides details related to the release that this issue/RFE will be addressed.
Unresolved : Release in which this issue/RFE will be addressed. Resolved: Release in which this issue/RFE has been resolved. Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.
If there are only repeated annotations, whether 1 or more, on a new, array or cast, they are not written to the class file. If one is not repeated and other are, they are okay.
Comments
verified in jdk8 b92
06-06-2013
fix in tl/langtools through commit for JDK-8013852
15-05-2013
Original commit: http://hg.openjdk.java.net/type-annotations/type-annotations/langtools/rev/ac33d03e35b8
There is a jtreg test at
http://cr.openjdk.java.net/~ssides/tests/TestNewCastArray.java
24-01-2013
It's not just 2 different repeated containers, but if there are only repeated annotations, whether 1 or 2. With arrays, it depends if it's a class member or local var.
A sample with comments:
import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
import static java.lang.annotation.ElementType.*;
class Test1 {
Test1(){}
Object o = new Integer(1);
//This has 0
Integer i1 = (@A @A Integer)o;
// This has 6 RuntimeVisibleTypeAnnotations: ok
String @A @A @B @B [] @A @A @B @B [] SA1 = new String @B [2] @A [2];
// This has 0 RuntimeVisibleTypeAnnotations, should be 2.
String [][] SA2 = new String @B @B [2] @A @A [2];
// This has 2, ok
String hello = new @A @A @B String("Hello");
// These have 0 annotations, should be 1,1,2
String hello1 = new @A @A String("Hello");
String hello2 = new @B @B String("Hello");
String hello3 = new @A @A @B @B String("Hello");
// This has 8, ok
String[][] test1(Test1 this, String param, String ... vararg) {
String @A @A @B [] @A @B @B [] sarray = new String @A @A @B[2] @A @B @B [2];
return sarray;
}
// but this has 0
String[][] test2(Test1 this, String param, String ... vararg) {
String @A @A [] @B @B [] sarray = new String @A @A [2] @A @A @B @B [2];
return sarray;
}
}
@Retention(RUNTIME)
@Target({TYPE_USE})
@ContainedBy( AC.class )
@interface A { }
@Retention(RUNTIME)
@Target({TYPE_USE})
@ContainerFor(A.class)
@interface AC { A[] value(); }
@Retention(RUNTIME)
@Target({TYPE_USE})
@ContainedBy( BC.class )
@interface B { }
@Retention(RUNTIME)
@Target({TYPE_USE})
@ContainerFor(B.class)
@interface BC { B[] value(); }
@Retention(RUNTIME)
@Target({TYPE_USE})
@interface C { }
@Retention(RUNTIME)
@Target({TYPE_USE,TYPE_PARAMETER,METHOD})
@ContainedBy(DC.class)
@interface D { }
@Retention(RUNTIME)
@Target({TYPE_USE,TYPE_PARAMETER,METHOD})
@ContainerFor(D.class)
@interface DC { D[] value(); }