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

javac-generated array and primitive-class annotation values crash getAnnotations

XMLWordPrintable

    • b51
    • generic, sparc
    • solaris_8, solaris_9

      Javac generates class files that violate the jsr175 format for annotations
      containing array-class values. Javac acts as if the reference was to a class
      literal for a class named "Array". This causes the readling library to fail
      at runtime, or worse yet return a reference to some user class named "Array".

      ==========$ cat T.java
      import java.lang.annotation.*;

      @Retention(RetentionPolicy.RUNTIME)
      @interface A {
          Class value();
      }

      @A(int[].class)
      class Main {
          public static void main(String[] args) {
              A a = Main.class.getAnnotation(A.class);
              System.out.println(a.value());
          }
      }
      ==========$ newjavac T.java
      ==========$ newjava Main
      Exception in thread "main" java.lang.TypeNotPresentException: Type [unknown] not present
              at sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:27)
              at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:56)
              at $Proxy1.value(Unknown Source)
              at Main.main(T.java:12)
      Caused by: java.lang.NoClassDefFoundError: Array
              at sun.reflect.ConstantPool.getClassAt0(Native Method)
              at sun.reflect.ConstantPool.getClassAt(ConstantPool.java:19)
              at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:309)
              at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:241)
              at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:184)
              at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:58)
              at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:43)
              at java.lang.Class.initAnnotationsIfNecessary(Class.java:2636)
              at java.lang.Class.getAnnotation(Class.java:2604)
              at Main.main(T.java:11)
      ==========$

            gafter Neal Gafter (Inactive)
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: