-
Bug
-
Resolution: Fixed
-
P4
-
8, 9, 10, 11
-
b25
-
x86_64
-
generic
A DESCRIPTION OF THE PROBLEM :
The type annotations on a generic receiver type's type variables are not readable via the reflection API despite this information being present in the class file. It is neither possible to read type annotations of an owner type, if existing.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the example code for a demonstration, there is simply no API present.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should be possible to receive the type annotation on the type variable within the code example what is currently impossible as the receiver type is treated as a non-parameterized type.
Instead, the returned receiver type should be an instance of ParameterizedType and the annotated type an instance of AnnotatedParameterizedType such that annotations of an owner type or on type parameters can be read.
All the necessary information is present in the class file.
ACTUAL -
The parameterized type is treated as a non-generic type.
---------- BEGIN SOURCE ----------
public class Foo<T> {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface SampleTypeVariable { }
void foo(Foo<@SampleTypeVariable T>this) { }
public static void main(String[] args) throws Exception {
Method foo = Foo.class.getDeclaredMethod("foo");
AnnotatedType receiverType = foo.getAnnotatedReceiverType();
// No chance to find out that the parameter type T was annotated, despite the annotation being present in the class file.
System.out.println(receiverType.getType() instanceof ParameterizedType);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None.
FREQUENCY : always
The type annotations on a generic receiver type's type variables are not readable via the reflection API despite this information being present in the class file. It is neither possible to read type annotations of an owner type, if existing.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the example code for a demonstration, there is simply no API present.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should be possible to receive the type annotation on the type variable within the code example what is currently impossible as the receiver type is treated as a non-parameterized type.
Instead, the returned receiver type should be an instance of ParameterizedType and the annotated type an instance of AnnotatedParameterizedType such that annotations of an owner type or on type parameters can be read.
All the necessary information is present in the class file.
ACTUAL -
The parameterized type is treated as a non-generic type.
---------- BEGIN SOURCE ----------
public class Foo<T> {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface SampleTypeVariable { }
void foo(Foo<@SampleTypeVariable T>this) { }
public static void main(String[] args) throws Exception {
Method foo = Foo.class.getDeclaredMethod("foo");
AnnotatedType receiverType = foo.getAnnotatedReceiverType();
// No chance to find out that the parameter type T was annotated, despite the annotation being present in the class file.
System.out.println(receiverType.getType() instanceof ParameterizedType);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
None.
FREQUENCY : always
- csr for
-
JDK-8228531 Change Executable.getAnnotatedReceiverType to return an instance of AnnotatedParameterizedType if appropriate
- Closed
- duplicates
-
JDK-8146957 It is impossible to query type annotations of a receiver type's parameters
- Closed
- relates to
-
JDK-8256693 getAnnotatedReceiverType parameterizes types too eagerly
- Closed