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

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

XMLWordPrintable

      One of tests for repeating annotations for Reflection API fails.
      Test URL: api/java_lang/Class/repanno/inheritanno/GetAnnotationsByTypeInheritedTests.html#GetAnnotationsByTypeInheritedTests[annotExtAnnotMixAnnotContCheckAnnotTest]


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

      public class Test {

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

              for(Ann j : jResult) {
                  System.out.println(j.value());
              }
          }
      }

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

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

      @Ann(0)
      class F {}

      @Ann(1) @AnnCont({@Ann(2), @Ann(3)})
      class J extends F {}
      -----------------------------------------------------------

      Output:
      -----------------------------------------------------------

      J @Ann count: 3, should be 4
      1
      2
      3

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

              Created:
              Updated:
              Resolved: