JDK-8199910 : Compiler crashes with -g option and variables of intersection type inferred by `var`
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 10
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2018-03-21
  • Updated: 2019-03-05
  • Resolved: 2018-03-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 10 JDK 11
10.0.2Fixed 11 b07Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Description

This code crashes the compiler with `-g` option.
```
public class Main {
    void m() {
        var s = java.util.List.of("a", 1);
    }
}
```

$ javac Main.java -g
C:\src>javac Main.java -g
java.lang.AssertionError: Unexpected intersection type: java.lang.Object&java.io.Serializable&java.lang.Comparable<? extends java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.enterInner(ClassWriter.java:1043)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.classReference(ClassWriter.java:312)
        at jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleClassSig(Types.java:5182)
        at jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:5114)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:291)
        at jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:5225)
        at jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleClassSig(Types.java:5201)
        at jdk.compiler/com.sun.tools.javac.code.Types$SignatureGenerator.assembleSig(Types.java:5114)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter$CWSignatureGenerator.assembleSig(ClassWriter.java:291)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.typeSig(ClassWriter.java:334)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeCode(ClassWriter.java:1271)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethod(ClassWriter.java:1158)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeMethods(ClassWriter.java:1653)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClassFile(ClassWriter.java:1761)
        at jdk.compiler/com.sun.tools.javac.jvm.ClassWriter.writeClass(ClassWriter.java:1679)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:749)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1627)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1595)
        at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:965)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:306)
        at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:165)
        at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
        at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)

The cause is about intersection. The variable type that is infered becomes as a type with intersection, and will crash the compiler when generating a debug info.
These are no problem.
  var s=List.of("a");
  var s=List.of("a", 1, Optional.empty());
  var s=List.of("a", 1, List.of());
Comments
[~robm], no problem, requested the backport for JDK-8200355 too.
19-04-2018

Thanks Jon. [~shade] Maurizio has mentioned that you will need both: http://hg.openjdk.java.net/jdk/jdk/rev/3556298e481d & http://hg.openjdk.java.net/jdk/jdk/rev/9925be430918 W.r.t. the latter, as its just a test fix, approval will be straightforward.
19-04-2018

[~robm] Any crash is serious ;-) This looks like a bug in a new feature, meaning that many folk may run into it while playing with that feature. Yay.
19-04-2018

Fix Request This seems to be a visible public bug (some people around be consider it a blocker for JDK 10 migration). Let's backport to JDK 10, adding jdk10u-fix-request tag.
18-04-2018