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

Issues with Type annotations on parameters of multiple type variable bound types

    Details

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      If the parameter of a type variable bound type is annotated and another bound of the same type variable defines the same type annotation on a parameter of the second bound with the same index, both type variables appear on both bounds and an exception is thrown.

      The code example demonstrates this problem.

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

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An exception is thrown.
      ACTUAL -
      No exception is thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.annotation.AnnotationFormatError: Duplicate annotation for class: interface net.bytebuddy.test.Sample: @net.bytebuddy.test.Sample()
      at sun.reflect.annotation.TypeAnnotationParser.mapTypeAnnotations(TypeAnnotationParser.java:360)
      at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedTypeBaseImpl.<init>(AnnotatedTypeFactory.java:139)
      at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedWildcardTypeImpl.<init>(AnnotatedTypeFactory.java:274)
      at sun.reflect.annotation.AnnotatedTypeFactory.buildAnnotatedType(AnnotatedTypeFactory.java:82)
      at sun.reflect.annotation.AnnotatedTypeFactory$AnnotatedParameterizedTypeImpl.getAnnotatedActualTypeArguments(AnnotatedTypeFactory.java:255)
      at net.bytebuddy.test.Foo.main(Foo.java:16)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      import java.lang.annotation.Target;
      import java.lang.reflect.AnnotatedParameterizedType;
      import java.util.List;
      import java.util.concurrent.Callable;

      public class Foo<T extends List<@Sample ?> & Callable<@Sample ?>> {

          public static void main(String[] args) {
              ((AnnotatedParameterizedType) Foo.class.getTypeParameters()[0].getAnnotatedBounds()[0]).getAnnotatedActualTypeArguments();
          }
      }

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

      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: