-
Resolution: Fixed
-
Priority: 👁 P3 - Major loss of function.
P3 -
Affects Version/s: 8, 11
-
Component/s: core-libs
| Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
|---|---|---|---|---|---|---|
| JDK-8195704 | 11 | Paul Sandoz | P3 | Resolved | Fixed | b01 |
| JDK-8197747 | 10u-cpu | Paul Sandoz | P3 | Resolved | Fixed | master |
| JDK-8200939 | 10.0.2 | Unassigned | P3 | Resolved | Fixed | b01 |
| JDK-8195943 | 10.0.1 | Paul Sandoz | P3 | Resolved | Fixed | b01 |
| JDK-8225328 | openjdk8u222 | Aleksey Shipilev | P3 | Resolved | Fixed | b05 |
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux smobile 3.16.0-33-generic #44-Ubuntu SMP Thu Mar 12 12:19:35 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Terminal short-circuit operations behave differently when called on stream produced by flatMap comparing to stream generated without involving flatMap.
Stream.of(1, 2, 3).filter(i -> { System.out.println(i); return true; }).findFirst() as expected will print single element of the stream, namely '1', as findFirst terminates once first element is produced (sequential stream case).
Unlike this,
Stream.of(1, 2, 3).flatMap(i -> Stream.of(i - 1, i, i + 1)).flatMap(i -> Stream.of(i - 1, i, i + 1)).filter(i -> { System.out.println(i); return true; }).findFirst()
will print 9 stream element which correspond to flattened stream corresponding to first element of source stream despite it is not needed for findFirst().
In case of finite stream, it is just inefficiency. However, if flatMap function produces infinite stream it will cause findFirst() never return which seems to be breaking short-circuiting behaviour of terminal operations on the stream.
From docs: "An intermediate operation is short-circuiting if, when presented with infinite input, it may produce a finite stream as a result."
"findFirst()
...
This is a short-circuiting terminal operation."
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
System.out.println("Infinite result: " +
Stream.of(0).flatMap(x->Stream.iterate(0, i->i+1)).findFirst());
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Infinite result: 0
ACTUAL -
It never prints anything as fails to unwind infinite stream.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
System.out.println(
"Correct Result: " +
Stream.of(1, 2, 3)
.filter(i -> {
System.out.println(i);
return true;
})
.findFirst()
.get()
);
System.out.println("-----------");
System.out.println(
"Correct Result with unnecessary filtering: " +
Stream.of(1, 2, 3)
.flatMap(i -> Stream.of(i - 1, i, i + 1))
.flatMap(i -> Stream.of(i - 1, i, i + 1))
.filter(i -> {
System.out.println(i);
return true;
})
.findFirst()
.get()
);
System.out.println("Result is never printed: " +
Stream.of(0).flatMap(x->Stream.iterate(0, i->i+1)).findFirst());
---------- END SOURCE ----------
- backported by
-
👁 Backport - A issue that is required to port a Bug or Feature into another product release. This issue type is generally associated with the main Bug/Feature to represent each individual release of the port.
JDK-8195704 Stream.flatMap() causes breaking of short-circuiting of terminal operations- 👁 P3 - Major loss of function.
- Resolved
- 👁 P3 - Major loss of function.
-
👁 Backport - A issue that is required to port a Bug or Feature into another product release. This issue type is generally associated with the main Bug/Feature to represent each individual release of the port.
JDK-8195943 Stream.flatMap() causes breaking of short-circuiting of terminal operations- 👁 P3 - Major loss of function.
- Resolved
- 👁 P3 - Major loss of function.
-
👁 Backport - A issue that is required to port a Bug or Feature into another product release. This issue type is generally associated with the main Bug/Feature to represent each individual release of the port.
JDK-8197747 Stream.flatMap() causes breaking of short-circuiting of terminal operations- 👁 P3 - Major loss of function.
- Resolved
- 👁 P3 - Major loss of function.
-
👁 Backport - A issue that is required to port a Bug or Feature into another product release. This issue type is generally associated with the main Bug/Feature to represent each individual release of the port.
JDK-8200939 Stream.flatMap() causes breaking of short-circuiting of terminal operations- 👁 P3 - Major loss of function.
- Resolved
- 👁 P3 - Major loss of function.
-
👁 Backport - A issue that is required to port a Bug or Feature into another product release. This issue type is generally associated with the main Bug/Feature to represent each individual release of the port.
JDK-8225328 Stream.flatMap() causes breaking of short-circuiting of terminal operations- 👁 P3 - Major loss of function.
- Resolved
- 👁 P3 - Major loss of function.
- duplicates
-
👁 Bug - A problem which impairs or prevents the functions of the product.
JDK-8196106 Support nested infinite or recursive flat mapped streams -
👁 Bug - A problem which impairs or prevents the functions of the product.
JDK-8149614 Stream.flatmap...findAny does not short-circuit as expected -
👁 Bug - A problem which impairs or prevents the functions of the product.
JDK-8079264 Non-terminating Stream.flatMap() with short-circuiting downstream operation -
👁 Bug - A problem which impairs or prevents the functions of the product.
JDK-8155217 Nested Stream.flatMap buffers the entire stream before processing it
- relates to
-
👁 Bug - A problem which impairs or prevents the functions of the product.
JDK-8229983 flatMap still prevents short circuiting when using .iterator() -
👁 Bug - A problem which impairs or prevents the functions of the product.
JDK-8189234 Unexpected StackOverflowError when using 'limit' on infinite list generated with recursive 'flatMap' call -
👁 Bug - A problem which impairs or prevents the functions of the product.
JDK-8267758 Double nested Stream.flatMap buffer the entire Stream before processing it
