JDK-8079264 : Non-terminating Stream.flatMap() with short-circuiting downstream operation
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.stream
  • Affected Version: 8u45
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2015-05-01
  • Updated: 2015-05-04
  • Resolved: 2015-05-04
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
While the following works as expected, printing out the infinite sequence of integers
	
Stream.of("").flatMap(x -> Stream.iterate(1, i -> i + 1)).forEach(System.out::println);

the following code prints out only the "1", but still does not terminate:
	
Stream.of("").flatMap(x -> Stream.iterate(1, i -> i + 1)).limit(1).forEach(System.out::println);

This may have the same cause as  Bug JDK-8075939 (flatMap does not do a cancellation check on the stream), but to my eyes the effect is even stranger.


REPRODUCIBILITY :
This bug can be reproduced always.


Comments
This is a duplicate of JDK-8075939. The case of a short-circuiting terminal operation (such as findFirst) or short-circuiting intermediate operation (such as limit) is the same.
04-05-2015