-
Bug
-
Resolution: Duplicate
-
P3
-
None
The handling of type annotations on the enclosing instance type of anonymous class supertypes is incorrect. Consider this example:
```
import java.lang.annotation.*;
class X {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
public @interface TA {
int value() default 0;
}
class Inner {}
private void f() {
class Local extends @TA(3) X.@TA(4) Inner {}
new Local();
}
private void g() {
new @TA(3) X.@TA(4) Inner() {};
}
}
```
Of the type annotations on the local class' supertype, @TA(4) is on the inner type 'Inner' (with location=[INNER_TYPE]) and @TA(3) is on the enclosing instance X.
$ javap -v -p X\$1Local
...
class X$1Local extends X$Inner
...
RuntimeVisibleTypeAnnotations:
0: #17(#18=I#19): CLASS_EXTENDS, type_index=65535, location=[INNER_TYPE]
X$TA(
value=4
)
1: #17(#18=I#20): CLASS_EXTENDS, type_index=65535
X$TA(
value=3
)
On the anonymous class' synthetic declaration, the annotations on the supertype are incorrectly both placed on the inner type 'Inner' (with location=[INNER_TYPE]). @TA(3) should be on the enclosing instance instead with an empty `location=[]`, the same as for the local class.
$ javap -v -p X\$1
...
class X$1 extends X$Inner
...
RuntimeVisibleTypeAnnotations:
0: #17(#18=I#19): CLASS_EXTENDS, type_index=65535, location=[INNER_TYPE]
X$TA(
value=4
)
1: #17(#18=I#20): CLASS_EXTENDS, type_index=65535, location=[INNER_TYPE]
X$TA(
value=3
)
```
import java.lang.annotation.*;
class X {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
public @interface TA {
int value() default 0;
}
class Inner {}
private void f() {
class Local extends @TA(3) X.@TA(4) Inner {}
new Local();
}
private void g() {
new @TA(3) X.@TA(4) Inner() {};
}
}
```
Of the type annotations on the local class' supertype, @TA(4) is on the inner type 'Inner' (with location=[INNER_TYPE]) and @TA(3) is on the enclosing instance X.
$ javap -v -p X\$1Local
...
class X$1Local extends X$Inner
...
RuntimeVisibleTypeAnnotations:
0: #17(#18=I#19): CLASS_EXTENDS, type_index=65535, location=[INNER_TYPE]
X$TA(
value=4
)
1: #17(#18=I#20): CLASS_EXTENDS, type_index=65535
X$TA(
value=3
)
On the anonymous class' synthetic declaration, the annotations on the supertype are incorrectly both placed on the inner type 'Inner' (with location=[INNER_TYPE]). @TA(3) should be on the enclosing instance instead with an empty `location=[]`, the same as for the local class.
$ javap -v -p X\$1
...
class X$1 extends X$Inner
...
RuntimeVisibleTypeAnnotations:
0: #17(#18=I#19): CLASS_EXTENDS, type_index=65535, location=[INNER_TYPE]
X$TA(
value=4
)
1: #17(#18=I#20): CLASS_EXTENDS, type_index=65535, location=[INNER_TYPE]
X$TA(
value=3
)
- duplicates
-
JDK-8198945 Invalid RuntimeVisibleTypeAnnotations for annotation on anonymous class type parameter
- Resolved