JDK-8044546 : Crash on faulty reduce/lambda
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u5,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-05-30
  • Updated: 2015-03-27
  • Resolved: 2014-06-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
8u40Fixed 9 b22Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b15, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux localhost 3.14.4-1-ARCH #1 SMP PREEMPT Tue May 13 16:41:39 CEST 2014 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
The compiler throws a NPE when it tries to compile my class containing the following line of code, which is likely malformed:
"return Arrays.stream(data).reduce(true, (a,b) -> a && b.length == len, (a,b) -> true);".
After commenting it out, it compiles just fine.

The stacktrace is:
java.lang.NullPointerException
	at com.sun.tools.javac.code.Types.isConvertible(Types.java:294)
	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:3818)
	at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3595)
	at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3502)
	at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3481)
	at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3468)
	at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3350)
	at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1836)
	at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:1697)
	at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1384)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:669)
	at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:685)
	at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1135)
	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:669)
	at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1028)
	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:669)
	at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4322)
	at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4232)
	at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4161)
	at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4136)
	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)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new class.
Create a new method in this class, which returns a boolean and takes an array argument.called "data".
Paste the following line in the method body: "return Arrays.stream(data).reduce(true, (a,b) -> a && b.length == len, (a,b) -> true);"
Try to compile the class

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An error message telling me why the code is malformed or successful compilation of the class if it isn't malformed.
ACTUAL -
A Null-Pointer Exception:


ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
	at com.sun.tools.javac.code.Types.isConvertible(Types.java:294)
	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:3818)
	at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3595)
	at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3502)
	at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3481)
	at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3468)
	at com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3350)
	at com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:1897)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1836)
	at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:1697)
	at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1384)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:669)
	at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:685)
	at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1135)
	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:669)
	at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1028)
	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:600)
	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:669)
	at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4322)
	at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4232)
	at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4161)
	at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4136)
	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.Arrays;                                                                                                              
                                                                                                                                      
public class Test                                                                                                                     
{                                                                                                                                     
        public boolean asd(Object[] data)                                                                                             
        {                                                                                                                             
                return Arrays.stream(data).reduce(true, (a,b) -> a && b.length == len, (a,b) -> true);                                
        }                                                                                                                             
}  
---------- END SOURCE ----------


Comments
regression introduced by JDK-8030741
11-06-2014

I think that this is a minimal, self contained test case: abstract class Test { boolean foo() { return bar(true, a -> {}); } abstract <T1> T1 bar(T1 t1, S<T1> s); } interface S<S1> { void baz(S1 s1); }
10-06-2014

This failure is reproducible with 9 java -version java version "1.9.0-ea" Java(TM) SE Runtime Environment (build 1.9.0-ea-b15) Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b15, mixed mode)
02-06-2014