JDK-8069181 : java.lang.AssertionError when compiling JDK 1.4 code in JDK 8
  • Type: Bug
  • Status: Resolved
  • Resolution: Fixed
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Affected Version: 7u65,8
  • Submit Date: 2015-01-16
  • Updated Date: 2015-09-29
  • Resolved Date: 2015-01-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 8
8u60 b01Resolved
Related Reports
Relates :  
Relates :  
Description
I am able to reproduce the issue using following sample code: 

TestEnum.java 
-------------------------------------------- 
import java.util.Enumeration; 
import java.util.Hashtable; 
public class TestEnum { 
        public static void main(String[] args) { 
                Hashtable hTable = new Hashtable(); 
                hTable.put("hello", "value"); 
                for (Enumeration enum = hTable.keys();;){ 
                        if(!enum.hasMoreElements()) 
                                break; 
                        enum.nextElement(); 
                } 
        } 
} 
-------------------------------------------- 
Compile using "-source 1.4" option 
This code compiles fine with jdk6 but fails with error with jdk8 
Comments
Label escape-old is added, since bug which cause problem (JDK-7160084), was introduced in JDK 8. (See Maurizio's comment: "This behavior has been harmless until recently, where a fix for type-checking enum constants was added (JDK-7160084).")
2015-04-07

Confirmed also with JDK 7 b65 (default on my Ubuntu setup).
2015-01-21

Code fails to compile with 8u40 rscalnan$ java -version java version "1.8.0_40-ea" Java(TM) SE Runtime Environment (build 1.8.0_40-ea-b21) Java HotSpot(TM) 64-Bit Server VM (build 25.40-b24, mixed mode) rscalnan$ javac -source 1.4 TestEnum.java warning: [options] bootstrap class path not set in conjunction with -source 1.4 warning: [options] source value 1.4 is obsolete and will be removed in a future release warning: [options] target value 1.4 is obsolete and will be removed in a future release warning: [options] To suppress warnings about obsolete options, use -Xlint:-options. TestEnum.java:7: warning: as of release 5, 'enum' is a keyword, and may not be used as an identifier for (Enumeration enum = hTable.keys();;){ ^ (use -source 5 or higher to use 'enum' as a keyword) TestEnum.java:8: warning: as of release 5, 'enum' is a keyword, and may not be used as an identifier if(!enum.hasMoreElements()) ^ (use -source 5 or higher to use 'enum' as a keyword) TestEnum.java:10: warning: as of release 5, 'enum' is a keyword, and may not be used as an identifier enum.nextElement(); ^ (use -source 5 or higher to use 'enum' as a keyword) An exception has occurred in the compiler (1.8.0_40-ea). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you. java.lang.AssertionError at com.sun.tools.javac.util.Assert.error(Assert.java:126) at com.sun.tools.javac.util.Assert.check(Assert.java:45) at com.sun.tools.javac.comp.Attr.attribIdentAsEnumType(Attr.java:821) at com.sun.tools.javac.comp.MemberEnter.visitVarDef(MemberEnter.java:647) at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852) at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:437) at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1015) at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852) at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566) at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:635) at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:651) at com.sun.tools.javac.comp.Attr.visitForLoop(Attr.java:1129) at com.sun.tools.javac.tree.JCTree$JCForLoop.accept(JCTree.java:1000) at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566) at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:635) at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:651) at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1105) at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909) at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566) at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:635) at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:994) at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778) at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:566) at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:635) at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4330) at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4240) at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4169) at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4144) at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248) at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860) at com.sun.tools.javac.main.Main.compile(Main.java:523) at com.sun.tools.javac.main.Main.compile(Main.java:381) at com.sun.tools.javac.main.Main.compile(Main.java:370) at com.sun.tools.javac.main.Main.compile(Main.java:361) at com.sun.tools.javac.Main.compile(Main.java:56) at com.sun.tools.javac.Main.main(Main.java:42)
2015-01-19

The problem has always been latent in javac code; code like: for (Foo enum = null : ... ) { ... } Has always been parsed slightly incorrectly, as the parser erroneously added the 'ENUM' flag to the 'enum' variable because of a bogus call to modifiersOpt() which was likely meant to return an empty list of modifiers; unfortunately if the variable is named 'enum' modifersOpt() is not a no-op, and results in surprising behavior. This behavior has been harmless until recently, where a fix for type-checking enum constants was added (JDK-7160084). Since that fix relies heavily on ENUM flags, the above parser bug started to cause spurious javac crashes (as javac erroneously thinks that a variable called 'enum' was an enum constant declaration). Also, since JDK 9 javac dropped support for JDK 1.4 features, this problem is no longer reproducible on latest JDK 9 branch. Since 'enum' can never be a valid variable name in JDK 9 compiler, the parser can be considered correct there, and no fix is needed in JDK 9. All JDKs prior to 9 in which a fix for JDK-7160084 has been backported are prone to this failure mode; according to the info in JBS, that means JDK 7 and 8.
2015-01-19

Ask submitter to try 8u40
2015-01-16