JDK-8073870 : Javac crash when compiliing type-inferred lambdas in reduce()
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u31
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2015-02-18
  • Updated: 2015-02-25
  • Resolved: 2015-02-25
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
3.13.0-45-generic #74-Ubuntu SMP Tue Jan 13 19:36:28 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
This program crashes javac: 

import java.util.TreeMap;

public class Main<T> {


    private int rebuild() {
        return new TreeMap<>().values().stream().reduce(0, (m, v) -> 0, (a, b) -> a + b);
    }

}




STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Save the following in a file called "Main.java", and then run "javac Main.java":

import java.util.TreeMap;

public class Main<T> {


    private int rebuild() {
        return new TreeMap<>().values().stream().reduce(0, (m, v) -> 0, (a, b) -> a + b);
    }

}


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Either a class file produced or a detailed compilation error
ACTUAL -
An error message indicating the compiler encountered an exception.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
An exception has occurred in the compiler (1.8.0_31). 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.NullPointerException
	at com.sun.tools.javac.code.Types.isConvertible(Types.java:290)
	at com.sun.tools.javac.comp.Check.assertConvertible(Check.java:922)
	at com.sun.tools.javac.comp.Check.checkMethod(Check.java:876)
	at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3838)
	at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3615)
	at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3522)
	at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3501)
	at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3488)
	at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3370)
	at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
	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.visitReturn(Attr.java:1704)
	at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1384)
	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.

---------- BEGIN SOURCE ----------
import java.util.TreeMap;

public class Main<T> {


    private int rebuild() {
        return new TreeMap<>().values().stream().reduce(0, (m, v) -> 0, (a, b) -> a + b);
    }

}

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

CUSTOMER SUBMITTED WORKAROUND :
Adding type annotations to the lambdas allows compilation.


Comments
Checked this for JDK 8u31 and could reproduce the exception: java.lang.NullPointerException at com.sun.tools.javac.code.Types.isConvertible(Types.java:290) at com.sun.tools.javac.comp.Check.assertConvertible(Check.java:922) at com.sun.tools.javac.comp.Check.checkMethod(Check.java:876) ------------------------------------------------------------- With 8u40 ea b23 and 9 ea b50 the exception is not reproducible. This is a duplicate of JDK-8044546 and resolved fixed in JDK 8u40 b01 and JDK 9 b22.
25-02-2015