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

compiler crash if annotation using an enum type defined inside the annotation

XMLWordPrintable

    • b46
    • generic, x86
    • generic, linux, windows_2000

      compiler crash if annotation using an enum type defined inside the annotation type

      Please see the code:-
      import java.lang.annoatation.*;

      @Retention(RetentionPolicy.RUNTIME)
      @interface NestedEnum1 {
           enum Quality { GOOD, BAD, AVERAGE }
         Quality value();
      }

      @NestedEnum1(NestedEnum1.Quality.GOOD) public class AnnotationDriverTest {
          
          public void assertion1() {
          
          
          }
          
          public static void main(String args[]) {
              AnnotationDriverTest ref = new AnnotationDriverTest();
              ref.assertion1();
          }

      }

      How to reproduce:-

      Compile annotation declaration in separate file say NesteEnum1.java
      it compiles.
      Now try to compile AnnotationDriverTest code in separate file say AnnotationDriverTest.java
      at this point compiler fails and gives the message described below:-
      An exception has occurred in the compiler (1.5.0-beta2). Please file a bug at the Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
      java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$ClassSymbol
              at com.sun.tools.javac.comp.Check.validateAnnotation(Check.java:1607)
              at com.sun.tools.javac.comp.Check.validateAnnotation(Check.java:1530)
              at com.sun.tools.javac.comp.Check.validateAnnotations(Check.java:1524)
              at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:2290)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2270)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2221)
              at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:410)
              at com.sun.tools.javac.main.Main.compile(Main.java:586)
              at com.sun.tools.javac.main.Main.compile(Main.java:538)
              at com.sun.tools.javac.Main.compile(Main.java:44)
              at com.sun.tools.javac.Main.main(Main.java:35)

      Environment Description:-

      Sol-9 JDK build Tiger-beta2 build40
       

      ----------------------------------------------------------------

      ###@###.### 2004-03-09

      Same bug reported by 2 CAP members:

      J2SE Version (please include all output from java -version flag):
        java version "1.5.0-beta2"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b40)
        Java HotSpot(TM) Client VM (build 1.5.0-beta2-b40, mixed mode)

      Does this problem occur on J2SE 1.3.x or 1.4.x? Yes / No (pick one)
        N/A

      Operating System Configuration Information (be specific):
        Windows 2000 Professional SP2

      Bug Description:
        javac crashes when asked to compile this convoluted example involving
        an enum with a constant-specific class body and annotations on both
        the enum type and the constant where the annotation's value is that
        same constant in both cases.

      Test program: FooEnum.java

          // start of FooEnum.java

          @FooAnnotation(FooEnum.CONSTANT)
          enum FooEnum {
              @FooAnnotation(CONSTANT)
              CONSTANT { }
          }

          @interface FooAnnotation {
              FooEnum value();
          }

          // end of FooEnum.java


      Steps to Reproduce (be specific):
        1) Save the file above as FooEnum.java
        2) javac -source 1.5 FooEnum.java
        3) Nod wisely at the stack trace:

      An exception has occurred in the compiler (1.5.0-beta2). Please file a
      bug at the Java Developer Connection (http://java.sun.com/cgi-bin/bugreport.cgi)
      after checking the Bug Parade for duplicates. Include your program and the
      following diagnostic in your report. Thank you.
      java.lang.NullPointerException
              at
      com.sun.tools.javac.comp.Check.validateAnnotation(Check.java:1604)
              at
      com.sun.tools.javac.comp.Check.validateAnnotation(Check.java:1530)
              at
      com.sun.tools.javac.comp.Check.validateAnnotations(Check.java:1524)
              at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:549)
              at com.sun.tools.javac.tree.Tree$VarDef.accept(Tree.java:511)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:256)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:291)
              at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:2337)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2270)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2241)
              at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2221)
              at com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:397)
              at com.sun.tools.javac.tree.Tree$ClassDef.accept(Tree.java:438)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:256)
              at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:291)
              at com.sun.tools.javac.comp.Attr.visitNewClass(Attr.java:1316)
              at com.sun.tools.javac.tree.Tree$NewClass.accept(Tree.java:840)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:256)
              at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:271)
              at com.sun.tools.javac.comp.Attr.evalInit(Attr.java:2058)
              at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:1693)
              at com.sun.tools.javac.tree.Tree$Select.accept(Tree.java:989)
              at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:256)
              at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:271)
              at
      com.sun.tools.javac.comp.Annotate.enterAttributeValue(Annotate.java:228)
              at
      com.sun.tools.javac.comp.Annotate.enterAnnotation(Annotate.java:165)
              at
      com.sun.tools.javac.comp.MemberEnter.enterAnnotations(MemberEnter.java:684)
              at
      com.sun.tools.javac.comp.MemberEnter.access$300(MemberEnter.java:39)
              at
      com.sun.tools.javac.comp.MemberEnter$5.enterAnnotation(MemberEnter.java:665)
              at com.sun.tools.javac.comp.Annotate.flush(Annotate.java:92)
              at com.sun.tools.javac.comp.Annotate.enterDone(Annotate.java:82)
              at com.sun.tools.javac.comp.Enter.main(Enter.java:394)
              at
      com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:382)
              at com.sun.tools.javac.main.Main.compile(Main.java:586)
              at com.sun.tools.javac.main.Main.compile(Main.java:538)
              at com.sun.tools.javac.Main.compile(Main.java:44)
              at com.sun.tools.javac.Main.main(Main.java:35)


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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: