JDK-8202469 : (ann) Type annotations on type variable bounds that are also type variables are lost
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 8,9,10,11
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-04-30
  • Updated: 2021-04-13
  • Resolved: 2020-03-18
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.

To download the current JDK release, click here.
JDK 15
15 b16Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
Type annotations on type variable bounds are not detected if the bounds are themselves type variables.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code example for a demonstration of the behavior.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The type annotations of both type variable bounds are detected.
ACTUAL -
The type annotations of a type variable that is bound by another type variable is not detected.

---------- BEGIN SOURCE ----------
public class Foo {

    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE_USE)
    @interface SampleTypeVariable { }

    <T, S extends @SampleTypeVariable T, U extends @SampleTypeVariable Object> void foo() { }

    public static void main(String[] args) throws Exception {
        Method foo = Foo.class.getDeclaredMethod("foo");
        TypeVariable<Method>[] typeParameters = foo.getTypeParameters();

        TypeVariable<?> s = typeParameters[1];
        AnnotatedType[] annotatedBoundsOfS = s.getAnnotatedBounds();
        System.out.println(annotatedBoundsOfS[0].getDeclaredAnnotations().length);

        TypeVariable<?> u = typeParameters[2];
        AnnotatedType[] annotatedBoundsOfU = u.getAnnotatedBounds();
        System.out.println(annotatedBoundsOfU[0].getDeclaredAnnotations().length);
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None.

FREQUENCY : always



Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/16d304873ab0 User: vromero Date: 2020-03-18 21:17:19 +0000
18-03-2020

This issue is reproducible on 8,9,10 and 11.Output is same on Eclipse as well Below is the result executed on 11 ea b11, == -sh-4.2$ /scratch/fairoz/JAVA/jdk11/jdk-11-ea+11/bin/javac Foo.java -sh-4.2$ /scratch/fairoz/JAVA/jdk11/jdk-11-ea+11/bin/java Foo 0 1 ==
01-05-2018