mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8193856
: takeWhile produces incorrect result with elements produced by flatMap
Reviewed-by: smarks
This commit is contained in:
parent
388f422efd
commit
e6680338c5
2 changed files with 36 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -95,7 +95,7 @@ final class WhileOps {
|
|||
|
||||
@Override
|
||||
public void accept(T t) {
|
||||
if (take = predicate.test(t)) {
|
||||
if (take && (take = predicate.test(t))) {
|
||||
downstream.accept(t);
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ final class WhileOps {
|
|||
|
||||
@Override
|
||||
public void accept(int t) {
|
||||
if (take = predicate.test(t)) {
|
||||
if (take && (take = predicate.test(t))) {
|
||||
downstream.accept(t);
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ final class WhileOps {
|
|||
|
||||
@Override
|
||||
public void accept(long t) {
|
||||
if (take = predicate.test(t)) {
|
||||
if (take && (take = predicate.test(t))) {
|
||||
downstream.accept(t);
|
||||
}
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ final class WhileOps {
|
|||
|
||||
@Override
|
||||
public void accept(double t) {
|
||||
if (take = predicate.test(t)) {
|
||||
if (take && (take = predicate.test(t))) {
|
||||
downstream.accept(t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -46,7 +46,7 @@ import java.util.stream.TestData;
|
|||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8071597
|
||||
* @bug 8071597 8193856
|
||||
*/
|
||||
@Test
|
||||
public class WhileOpTest extends OpTestCase {
|
||||
|
@ -361,4 +361,33 @@ public class WhileOpTest extends OpTestCase {
|
|||
}
|
||||
assertTrue(isClosed.get());
|
||||
}
|
||||
|
||||
@Test(groups = { "serialization-hostile" })
|
||||
public void testFlatMapThenTake() {
|
||||
TestData.OfRef<Integer> range = TestData.Factory.ofSupplier(
|
||||
"range", () -> IntStream.range(0, 100).boxed());
|
||||
|
||||
exerciseOpsMulti(range,
|
||||
// Reference result
|
||||
s -> s.takeWhile(e -> e != 50),
|
||||
// For other results collect into array,
|
||||
// stream the single array (not the elements),
|
||||
// then flat map to stream the array elements
|
||||
s -> Stream.<Integer[]>of(s.toArray(Integer[]::new)).
|
||||
flatMap(Stream::of).
|
||||
takeWhile(e -> e != 50),
|
||||
s -> Stream.of(s.mapToInt(e -> e).toArray()).
|
||||
flatMapToInt(IntStream::of).
|
||||
takeWhile(e -> e != 50).
|
||||
mapToObj(e -> e),
|
||||
s -> Stream.of(s.mapToLong(e -> e).toArray()).
|
||||
flatMapToLong(LongStream::of).
|
||||
takeWhile(e -> e != 50L).
|
||||
mapToObj(e -> (int) e),
|
||||
s -> Stream.of(s.mapToDouble(e -> e).toArray()).
|
||||
flatMapToDouble(DoubleStream::of).
|
||||
takeWhile(e -> e != 50.0).
|
||||
mapToObj(e -> (int) e)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue