JDK-8071291 : Compiler crashes trying to cast UnionType to IntersectionClassType
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u25
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2015-01-22
  • Updated: 2016-07-18
  • Resolved: 2015-02-23
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
8u72Fixed 9 b53Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
just try to build their product with Java 8 and got the following error below 
from java compiler:


class.only:

    [mkdir] Created dir: L:\arb_wcArbortext\SIS\RulesPartsEditor\src_gen
    [javac] Compiling 106 source files to 
L:\arb_wcArbortext\SIS\RulesPartsEditor\codebase
    [javac] Annotation processing round 1 complete -- 5 file(s) generated.
    [javac] Annotation processing round 2 complete -- 1 file(s) generated.
    [javac] Annotation processing generation COMPLETE.  ALL ERRORS BEYOND 
THIS POINT ARE REAL!!!
    [javac] An exception has occurred in the compiler (1.8.0_25). 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.
    [javac] java.lang.ClassCastException: 
com.sun.tools.javac.code.Type$UnionClassType cannot be cast to 
com.sun.tools.javac.code.Type$IntersectionClassType
    [javac]              at 
com.sun.tools.javac.code.Types$8.visitClassType(Types.java:1540)
    [javac]              at 
com.sun.tools.javac.code.Types$8.visitClassType(Types.java:1497)
    [javac]              at 
com.sun.tools.javac.code.Type$ClassType.accept(Type.java:778)
    [javac]              at 
com.sun.tools.javac.code.Types$DefaultTypeVisitor.visit(Types.java:4451)
    [javac]              at 
com.sun.tools.javac.code.Types.isCastable(Types.java:1488)
    [javac]              at 
com.sun.tools.javac.comp.Check.checkCastable(Check.java:568)
    [javac]              at 
com.sun.tools.javac.comp.Check.checkCastable(Check.java:565)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitTypeTest(Attr.java:3146)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCInstanceOf.accept(JCTree.java:1840)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitParens(Attr.java:2990)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCParens.accept(JCTree.java:1661)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:649)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitIf(Attr.java:1599)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1269)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitTry(Attr.java:1395)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCTry.accept(JCTree.java:1173)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitIf(Attr.java:1600)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCIf.accept(JCTree.java:1269)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitForeachLoop(Attr.java:1207)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCEnhancedForLoop.accept(JCTree.java:1035)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
    [javac]              at 
com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1035)
    [javac]              at 
com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4342)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4252)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4181)
    [javac]              at 
com.sun.tools.javac.comp.Attr.attrib(Attr.java:4156)
    [javac]              at 
com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
    [javac]              at 
com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
    [javac]              at 
com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
    [javac]              at 
com.sun.tools.javac.main.Main.compile(Main.java:523)
    [javac]              at 
com.sun.tools.javac.main.Main.compile(Main.java:381)
    [javac]              at 
com.sun.tools.javac.main.Main.compile(Main.java:370)
    [javac]              at 
com.sun.tools.javac.main.Main.compile(Main.java:361)
    [javac]              at com.sun.tools.javac.Main.compile(Main.java:56)
    [javac]              at com.sun.tools.javac.Main.main(Main.java:42)



Comments
Further issue reported by the submitter: run into other javac crashes along these lines, e.g. with: } catch (WTPropertyVetoException | WTException e) { throw (e instanceof WTException) ? (WTException) e : new WTException(e); } not managed to produce a standalone test case, unfortunately. The common element seems to be doing something with a multi-catch followed immediately by an instanceof check on the exception in the catch that could be better handled as part of the catch. The code in each case should be much better expressed in other ways. Still having the compiler crash is not appropriate or helpful. What's worse the crash gives no indication of the source file or line being processed at the time.
25-02-2015

More comment from the CAP member - } catch (WTPropertyVetoException | WTException e) { if (e instanceof NotAuthorizedException) { <------- the crash occurs return result; } result.setStatus(FormProcessingStatus.FAILURE); result.addException(e); return result; } if change to } catch (NotAuthorizedException e) { return result; } catch (WTPropertyVetoException | WTException e) { result.setStatus(FormProcessingStatus.FAILURE); result.addException(e); return result; } where things work fine. NotAuthorizedException is a subclass of WTException here.
22-01-2015

If the code that is failing has a shape that is similar to the reduced test case above, the workaround would be to unwind the multi-catch statement as follows: try { ... } catch (Exception1 e) { //here x is instanceof Exception1 } catch (Exception2 e) { ... }
22-01-2015

Reproducible with the following code: interface A { } class Exception1 extends Exception implements A { } class Exception2 extends Exception implements A { } class Test { void test(boolean cond) { try { if (cond) { throw new Exception1(); } else { throw new Exception2(); } } catch (Exception1|Exception2 x) { if (x instanceof Exception1) { } } } }
22-01-2015