JDK-8066971 : "java.lang.AssertionError: Cannot get here" in javac
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u20
  • Priority: P4
  • Status: Resolved
  • Resolution: Cannot Reproduce
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-08-28
  • Updated: 2017-05-12
  • Resolved: 2017-05-12
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.
Other
tbd_majorResolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

A DESCRIPTION OF THE PROBLEM :
When trying to compile this class:

public class AssertionInJavac {
    public static void main(String[] args) {
        List<StringBuilder> members = getCollection(getCollection(Collections.emptyList(), ArrayList::new, AssertionInJavac::identity), ArrayList::new, AssertionInJavac::identity);
    }

    @SuppressWarnings("unused")
    public static <T, C extends Collection<T>> C getCollection(C defaultValue, final Supplier<C> target, final Function<? super T, ? extends CharSequence> toString) {
        return null;
    }

    public static <T> T identity(T in) {
        return in;
    }
}

the compiler fails with an java.lang.AssertionError: Cannot get here


ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.AssertionError: Cannot get here
        at com.sun.tools.javac.util.Assert.error(Assert.java:133)
        at com.sun.tools.javac.comp.DeferredAttr$DeferredAttrNode.process(DeferredAttr.java:557)
        at com.sun.tools.javac.comp.DeferredAttr$DeferredAttrContext.complete(DeferredAttr.java:479)
        at com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:182)
        at com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:564)
        at com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1431)
        at com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1618)
        at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1689)
        at com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1662)
        at com.sun.tools.javac.comp.Resolve.findFun(Resolve.java:1822)
        at com.sun.tools.javac.comp.Resolve$8.doLookup(Resolve.java:2383)
        at com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3074)
        at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3325)
        at com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3310)
        at com.sun.tools.javac.comp.Resolve.resolveMethod(Resolve.java:2379)
        at com.sun.tools.javac.comp.Attr.visitIdent(Attr.java:3170)
        at com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2011)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
        at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1843)
        at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
        at com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:649)
        at com.sun.tools.javac.comp.Attr.visitVarDef(Attr.java:1093)
        at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:852)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
        at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
        at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
        at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
        at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1035)
        at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
        at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
        at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
        at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4342)
        at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4252)
        at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4181)
        at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4156)
        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)

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
The first parameter of the outer invocation of getCollection() can be refactored to a local variable (the compiler then complains about incompatibility of inferred types, which I think is wrong (and ecj concurs), but does not crash).

If AssertionInJavac::identity method references are replaced with UnaryOperator.<StringBuilder> identity(), it compiles fine (but not with UnaryOperator.identity() - another type inference error).


Comments
already fixed in 9
12-05-2017

This issue is reproducible with JDK 8u25 as well. Error with JDK 8u40 was different - "java.lang.AssertionError: attribution shouldn't be happening here". JDK 9 compiled the code successfully though.
09-12-2014