JDK-8065424 : Compiler Error
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u20,8u25
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2014-11-11
  • Updated: 2014-11-20
  • Resolved: 2014-11-20
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
8u40Resolved
Related Reports
Duplicate :  
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)

ADDITIONAL OS VERSION INFORMATION :
OS X Version 10.9.5

A DESCRIPTION OF THE PROBLEM :
The compiler fails to compile a piece of valid Java code:

Give the following Stream

Stream<String> items = Arrays.asList("1","2","3","4","5").stream();

The following line fails to compile:

int res = items.reduce(0, (i,s) -> i + Integer.valueOf(s), (a,b) -> a + b);

Whereas the following succeed:

Integer res = items.reduce(0, (i,s) -> i + Integer.valueOf(s), (a,b) -> a + b);

The error the compiler generates when using the primitive integer version is the following:



REGRESSION.  Last worked in version 8u11

ADDITIONAL REGRESSION INFORMATION: 
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)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Simply try to compile this:

Stream<String> items = Arrays.asList("1","2","3","4","5").stream();
int res = items.reduce(0, (i,s) -> i + Integer.valueOf(s), (a,b) -> a + b);

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should compile without problems.
ACTUAL -
An exception has occurred in the compiler (1.8.0_25).

ERROR MESSAGES/STACK TRACES THAT OCCUR :
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.
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.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.

---------- BEGIN SOURCE ----------
public static void main(String[] args) {

    Stream<String> items = Arrays.asList("1","2","3","4","5").stream();

    int res = items.reduce(0, (i,s) -> i + Integer.valueOf(s), (a,b) -> a + b);
    System.out.println(res);

  }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The workaround is to use wrapper objects.

Stream<String> items = Arrays.asList("1","2","3","4","5").stream();
Integer res = items.reduce(0, (i,s) -> i + Integer.valueOf(s), (a,b) -> a + b);



Comments
Appears to be duplicate of JDK-8044546.
20-11-2014

I don't understand why we have an error entry as descriptive as "Compiler Error"
20-11-2014

The code compiles fine with JDK 8u5, 8u11, 8u40 and 9. However, it threw NPE with JDK 8u20 and 8u25. It failed to compile with errors in JDK 7u67 and 7u72.
20-11-2014