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

(ann) Type annotation on parameterized type's owner type is not located correctly

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      If an owner type of a nested parameterized type is annotated, the type annotation is not accessible via the reflection API.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the example code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The type annotation is found for foo and it is found for the correct type for bar.
      ACTUAL -
      The type annotation is not found for foo and found for the incorrect type for bar.

      ---------- BEGIN SOURCE ----------
      public class Foo {

          @Retention(RetentionPolicy.RUNTIME)
          @Target(ElementType.TYPE_USE)
          @interface SampleTypeAnnotation { }

          static class GenericNested<T> {
              class Inner { }
          }

          @SampleTypeAnnotation GenericNested<?>. Inner foo;

          GenericNested<?>.@SampleTypeAnnotation Inner bar;

          public static void main(String[] args) throws Exception {
              Field foo = Foo.class.getDeclaredField("foo");
              System.out.println(foo.getAnnotatedType().getType().toString());
              System.out.println(foo.getAnnotatedType().getAnnotations().length);
              System.out.println(foo.getAnnotatedType().getAnnotatedOwnerType().getType().toString());
              System.out.println(foo.getAnnotatedType().getAnnotatedOwnerType().getAnnotations().length);

              Field bar = Foo.class.getDeclaredField("bar");
              System.out.println(bar.getAnnotatedType().getType().toString());
              System.out.println(bar.getAnnotatedType().getAnnotations().length);
              System.out.println(bar.getAnnotatedType().getAnnotatedOwnerType().getType().toString());
              System.out.println(bar.getAnnotatedType().getAnnotatedOwnerType().getAnnotations().length);
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: