-
Bug
-
Resolution: Fixed
-
P2
-
9
-
None
-
b38
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8194610 | 11 | Paul Sandoz | P2 | Resolved | Fixed | b01 |
The following code:
String[][] ss = {{"a", "b"}, {"c", "d"}};
Stream.of(ss).
flatMap(Arrays::stream).
takeWhile(
e -> e != "c").
forEachOrdered(System.out::println);
will output:
a
b
d
takeWhile is incorrectly assuming that an upstream operation supports and honors cancellation, which unfortunately is not the case for flatMap. (It's tricky to support given flatMap operates on a public Stream whose implementation may not be known. forEach variants supporting cancellation is required).
The current implementation of while op Sink::accept is:
@Override
public void accept(T t) {
if (take = predicate.test(t)) {
downstream.accept(t);
}
}
it should be:
@Override
public void accept(T t) {
if (take && (take = predicate.test(t))) {
downstream.accept(t);
}
}
String[][] ss = {{"a", "b"}, {"c", "d"}};
Stream.of(ss).
flatMap(Arrays::stream).
takeWhile(
e -> e != "c").
forEachOrdered(System.out::println);
will output:
a
b
d
takeWhile is incorrectly assuming that an upstream operation supports and honors cancellation, which unfortunately is not the case for flatMap. (It's tricky to support given flatMap operates on a public Stream whose implementation may not be known. forEach variants supporting cancellation is required).
The current implementation of while op Sink::accept is:
@Override
public void accept(T t) {
if (take = predicate.test(t)) {
downstream.accept(t);
}
}
it should be:
@Override
public void accept(T t) {
if (take && (take = predicate.test(t))) {
downstream.accept(t);
}
}
- backported by
-
JDK-8194610 takeWhile produces incorrect result with elements produced by flatMap
-
- Resolved
-