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

(reflect) unpredictable order of result of getAnnotations

    Details

      Description

      The ordering of annotations are not always stable, for a declaration:

      @Foo(0)
      @FooContainer(value={@Foo(1),@Foo(2)})
      class A {}

      A.class.getAnnotations() will vary the order of Foo and FooContainer as shown by the run of the simple reproducer attached:

      $ java -version
      java version "1.7.0_45"
      Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
      jbf-mba:t jbf$ while java T; do echo .; done
      .
      .
      .
      .
      .
      .
      .
      Got: [@Foo(value=0), @FooContainer(value=[@Foo(value=1), @Foo(value=2)])]
      Expecting: [@FooContainer(value=[@Foo(value=1), @Foo(value=2)]), @Foo(value=0)]
      Exception in thread "main" java.lang.RuntimeException: Woha
      at T.main(T.java:27)

        Attachments

        1. T.java
          0.7 kB
          Joel Borggrén-Franck

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                mnunez Matherey Nunez (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: