Duplicate :
|
Name: rmT116609 Date: 03/10/2004 FULL PRODUCT VERSION : Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c) Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode) ADDITIONAL OS VERSION INFORMATION : Linux localhost.localdomain 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686 i386 GNU/Linux A DESCRIPTION OF THE PROBLEM : A programmer can write an inner class that subclasses the type java.lang.Enum (itself illegal!). A statement to instantiate this class, e.g. by calling the no-arg public constructor, will cause the compiler to crash. Specifically the constructor statement must come prior to the declaration of the inner class (the compiler will produce a correct error message if the constructor statement comes after). STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : see code example. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - An error message from javac such as 'enum types may not be instantiated'. ACTUAL - javac crashes (see error message). ERROR MESSAGES/STACK TRACES THAT OCCUR : [alexis@localhost examples]$ javac -source 1.5 -target 1.5 Outer.java An exception has occurred in the compiler (1.5.0-beta). 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.Lower.boxArgs(Lower.java:2312) at com.sun.tools.javac.comp.Lower.visitNewClass(Lower.java:2095) at com.sun.tools.javac.tree.Tree$NewClass.accept(Tree.java:841) at com.sun.tools.javac.comp.Lower.translate(Lower.java:1739) at com.sun.tools.javac.comp.Lower.translate(Lower.java:1751) at com.sun.tools.javac.comp.Lower.visitVarDef(Lower.java:2708) at com.sun.tools.javac.tree.Tree$VarDef.accept(Tree.java:511) at com.sun.tools.javac.comp.Lower.translate(Lower.java:1739) at com.sun.tools.javac.comp.Lower.visitClassDef(Lower.java:1821) at com.sun.tools.javac.tree.Tree$ClassDef.accept(Tree.java:438) at com.sun.tools.javac.comp.Lower.translate(Lower.java:1739) at com.sun.tools.javac.comp.Lower.translate(Lower.java:1759) at com.sun.tools.javac.comp.Lower.translateTopLevelClass(Lower.java:2830) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:455) at com.sun.tools.javac.main.Main.compile(Main.java:593) at com.sun.tools.javac.main.Main.compile(Main.java:545) at com.sun.tools.javac.Main.compile(Main.java:44) at com.sun.tools.javac.Main.main(Main.java:35) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public class Outer { // The line below will crash the compiler: Inner inner = new Inner(); // The line below is an illegal declaration (but the compiler allows it): class Inner extends Enum { } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Do not write inner classes that extend java.lang.Enum (this is illegal anyway). (Incident Review ID: 242873) ======================================================================