JDK-8038023 : Compiler crash: ClassCastException
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u20
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2014-03-20
  • Updated: 2014-07-29
  • Resolved: 2014-04-30
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 Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20 b13Fixed 9Fixed
Description
hFULL PRODUCT VERSION :
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b05)
Java HotSpot(TM) Client VM (build 25.20-b05, mixed mode, sharing)

EXTRA RELEVANT SYSTEM CONFIGURATION :
Compiling with IntelliJIdea 12.1.6

A DESCRIPTION OF THE PROBLEM :
When using JDK 1.8.0_20 to compile JSPs that reference classes compiled with IntelliJIdea 12.1.6 with @NotNull assertions added I get a compiler crash.  I provide a reduced test case, 

REGRESSION.  Last worked in version 8

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b05)
Java HotSpot(TM) Client VM (build 25.20-b05, mixed mode, sharing)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile BugImported.java with IntelliJIdea 12.1.6 using 1.8.0_20 as the project JDK, or use the attached BugImported.class
2. From the command line, compile Bug.java with the class file from step 1 in the classpath


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Bug.java should compile correctly
ACTUAL -
The compiler crashes

ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (1.8.0_20-ea). Please file a bug at the Java Developer Connection (http://java
or duplicates. Include your program and the following diagnostic in your report.  Thank you.
java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$ClassSymbol cannot be cast to com.sun.tools.javac.util.Name
        at com.sun.tools.javac.jvm.ClassReader.readName(ClassReader.java:597)
        at com.sun.tools.javac.jvm.ClassReader.setParameterNames(ClassReader.java:2125)
        at com.sun.tools.javac.jvm.ClassReader.readMethod(ClassReader.java:2026)
        at com.sun.tools.javac.jvm.ClassReader.readClass(ClassReader.java:2229)
        at com.sun.tools.javac.jvm.ClassReader.readClassFile(ClassReader.java:2301)
        at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:2488)
        at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:2419)
        at com.sun.tools.javac.jvm.ClassReader.access$000(ClassReader.java:76)
        at com.sun.tools.javac.jvm.ClassReader$1.complete(ClassReader.java:240)
        at com.sun.tools.javac.code.Symbol.complete(Symbol.java:560)
        at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1024)
        at com.sun.tools.javac.jvm.ClassReader.loadClass(ClassReader.java:2600)
        at com.sun.tools.javac.comp.Resolve.loadClass(Resolve.java:1863)
        at com.sun.tools.javac.comp.Resolve.findIdentInPackage(Resolve.java:2102)
        at com.sun.tools.javac.comp.Attr.selectSym(Attr.java:3358)
        at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3257)
        at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1891)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:596)
        at com.sun.tools.javac.comp.Attr.attribType(Attr.java:658)
        at com.sun.tools.javac.comp.Attr.attribType(Attr.java:651)
        at com.sun.tools.javac.comp.MemberEnter.attribImportType(MemberEnter.java:836)
        at com.sun.tools.javac.comp.MemberEnter.visitImport(MemberEnter.java:556)
        at com.sun.tools.javac.tree.JCTree$JCImport.accept(JCTree.java:571)
        at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:435)
        at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:447)
        at com.sun.tools.javac.comp.MemberEnter.visitTopLevel(MemberEnter.java:526)
        at com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:518)
        at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:435)
        at com.sun.tools.javac.comp.MemberEnter.complete(MemberEnter.java:1038)
        at com.sun.tools.javac.code.Symbol.complete(Symbol.java:560)
        at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1024)
        at com.sun.tools.javac.comp.Enter.complete(Enter.java:497)
        at com.sun.tools.javac.comp.Enter.main(Enter.java:475)
        at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:985)
        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)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
---- File BugImported.class (base64 encoded)

yv66vgAAADQAOgEAD2J1Zy9CdWdJbXBvcnRlZAcAAQEAEGphdmEvbGFuZy9PYmplY3QHAAMBABBC
dWdJbXBvcnRlZC5qYXZhAQAGPGluaXQ+AQADKClWDAAGAAcKAAQACAEABHRoaXMBABFMYnVnL0J1
Z0ltcG9ydGVkOwEACWdldFN0cmluZwEAJihMamF2YS9sYW5nL1N0cmluZzspTGphdmEvbGFuZy9T
dHJpbmc7AQAjTG9yZy9qZXRicmFpbnMvYW5ub3RhdGlvbnMvTm90TnVsbDsBACJqYXZhL2xhbmcv
SWxsZWdhbEFyZ3VtZW50RXhjZXB0aW9uBwAPAQBPQXJndW1lbnQgMCBmb3IgQE5vdE51bGwgcGFy
YW1ldGVyIG9mIGJ1Zy9CdWdJbXBvcnRlZC5nZXRTdHJpbmcgbXVzdCBub3QgYmUgbnVsbAgAEQEA
FShMamF2YS9sYW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ABAACwARADgAAAAFAQAZAAAAAQA5AAAAAgAF


---- File Bug.java

package bug;

import bug.BugImported;

public class Bug
{
}


--- For reference, file BugImported.java

package bug;

import org.jetbrains.annotations.NotNull;

public class BugImported
{
	@NotNull
	private static String getString (@NotNull final String string)
	{
		return "";
	}


	public static void main (String[] args)
	{
		System.out.println (getString (""));
	}

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Disable "Add @NotNull assertions" in compile options for IntelliJIdea


Comments
Just to clarify: this bug is a poor failure condition in javac when encountering an invalid MethodParameter table. In this case, the invalid table is generated by intelliJ's bytecode instrumentation, and the failure occurs in javac during annotation processing. Javac can help here by producing a better failure indicating that the classfile is invalid. The intelliJ bytecode instrumentation issue is being tracked here: http://youtrack.jetbrains.com/issue/IDEA-123001.
16-04-2014

Please see: http://mail.openjdk.java.net/pipermail/compiler-dev/2014-March/008651.html and: http://mail.openjdk.java.net/pipermail/compiler-dev/2014-March/008678.html If the classfile that is being read is invalid, then javac should complain about that, I think (class cast exception is not the best way to complain about a broken classfile, of course).
07-04-2014

Additional information from Robert Gibson: "the issue only manifests itself when I also pass "-parameters" option to the compiler (along with the IntelliJ bytecode fiddling). javap -c -verbose shows that the "MethodParameters" table shows a classname instead of the real method parameter name."
07-04-2014