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

Type annotations on cast not reflected correctly by javap

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 8
    • tools
    • 8
    • b91
    • Verified

    Description


      The type annotations on a cast are not reflected in the output of javap unless the cast
      is annotated with more the one annotation types. Repeating the same annotation is not
      enough, however, two annotations with different retention policy is enough.

      To reproduce, compile the following class and run javap, and observe the lack of
      CAST type annotation for the fiels "not_ok".

      Note: I'm filing the problem against javap, as it was uncovered in javap testing.
      It' is likely, however, that the problem is at the classfile level.


      import java.lang.annotation.*;
      class Test {

          @Repeatable(As.class)
          @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
          @Retention(RetentionPolicy.CLASS)
          @interface A {
              Class f() default int.class;
          }
          @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
          @Retention(RetentionPolicy.CLASS)
          @interface As { A[] value(); }

          @Repeatable(Bs.class)
          @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
          @Retention(RetentionPolicy.CLASS)
          @interface B {
              Class f() default int.class;
          }
          @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
          @Retention(RetentionPolicy.CLASS)
          @interface Bs { B[] value(); }

          @Repeatable(Cs.class)
          @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
          @Retention(RetentionPolicy.RUNTIME)
          @interface C {
              Class f() default int.class;
          }
          @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
          @Retention(RetentionPolicy.RUNTIME)
          @interface Cs { C[] value(); }
          static String so = "hello world";

          public @A Object not_ok = (@A @A String) Test.so;
          public @A Object ok = (@A @B String) Test.so;
          public @A Object also_ok = (@A @C String) Test.so;
      }

      Attachments

        Issue Links

          Activity

            People

              jfranck Joel Borggrén-Franck (Inactive)
              strarup Peter Jensen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: