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

j.l.Class.getAnnotationsByType(Class) returns wrong result for inherited repeating annotations

XMLWordPrintable

      j.l.Class.getAnnotationsByType(Class) returns wrong result for inherited repeating annotations.
      JCK tests fail for jdk8-b99.

      Minimized test:
      --------------------------------------------------

      public class Test {

          public static void main(String[] args) {
              Ann[] bResult = B.class.getAnnotationsByType(Ann.class);
              System.out.println("B @Ann count: " + bResult.length + ", should be 4");

              Ann[] dResult = D.class.getAnnotationsByType(Ann.class);
              System.out.println("D @Ann count: " + dResult.length + ", should be 2");
          }
      }

      @Retention(RetentionPolicy.RUNTIME)
      @Repeatable(AnnCont.class)
      @Inherited
      @interface Ann {
          int value();
      }

      @Retention(RetentionPolicy.RUNTIME)
      @Inherited
      @interface AnnCont {
          Ann[] value();
      }

      @Ann(0) @Ann(1)
      class A {}

      @Ann(2) @Ann(3)
      class B extends A {}

      @Ann(0)
      class F {}

      @Ann(2)
      class D extends F {}
      --------------------------------------------------

      Output:
      --------------------------------------------------
      B @Ann count: 2, should be 4
      D @Ann count: 1, should be 2

            alundblad Andreas Lundblad (Inactive)
            evotchen Elena Votchennikova (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: