In the following example the method 'f' has an incorrect CLASS_EXTENDS RuntimeVisibleTypeAnnotations attribute. The annotation is actually associated with the type argument of an anonymous class inside the method body.
===
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.Callable;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@interface Foo {}
class T {
private void f() {
new Callable<@Foo Object>() {
public Object call() {
return null;
}
};
}
}
===
$ javac -fullversion T.java && /google/data/ro/
javac full version "11-ea+3"
$ javap -p -v T
...
private void f();
descriptor: ()V
flags: (0x0002) ACC_PRIVATE
Code:
stack=3, locals=1, args_size=1
0: new #2 // class T$1
3: dup
4: aload_0
5: invokespecial #3 // Method T$1."<init>":(LT;)V
8: pop
9: return
LineNumberTable:
line 13: 0
line 18: 9
RuntimeVisibleTypeAnnotations:
0: #13(): CLASS_EXTENDS, type_index=0, location=[TYPE_ARGUMENT(0)]
Foo
===
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.Callable;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@interface Foo {}
class T {
private void f() {
new Callable<@Foo Object>() {
public Object call() {
return null;
}
};
}
}
===
$ javac -fullversion T.java && /google/data/ro/
javac full version "11-ea+3"
$ javap -p -v T
...
private void f();
descriptor: ()V
flags: (0x0002) ACC_PRIVATE
Code:
stack=3, locals=1, args_size=1
0: new #2 // class T$1
3: dup
4: aload_0
5: invokespecial #3 // Method T$1."<init>":(LT;)V
8: pop
9: return
LineNumberTable:
line 13: 0
line 18: 9
RuntimeVisibleTypeAnnotations:
0: #13(): CLASS_EXTENDS, type_index=0, location=[TYPE_ARGUMENT(0)]
Foo
- duplicates
-
JDK-8207018 Incorrect handling of type annotations on enclosing instances of anonymous class supertypes
- Closed