Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8202469

(ann) Type annotations on type variable bounds that are also type variables are lost

XMLWordPrintable

    • b16
    • x86_64
    • generic
    • Verified

      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


            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: