RFR 8044047: Missing null pointer checks for streams
Paul Sandoz
paul.sandoz at oracle.com
Wed Jul 2 12:01:40 UTC 2014
Hi,
Please review this fix for some missing null-checks in stream code:
http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8044047-null-checks/webrev/
https://bugs.openjdk.java.net/browse/JDK-8044047
I also boosted some of the primitive summary statistic tests.
Unfortunately the refactoring of some test names resulted in disassociation between old and new (not quite sure why in this case), so diffs for renamed tests are below.
Paul.
jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/ExplodeOpTest.java
->
jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/FlatMapOpTest.java
2c2
< * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
---
> * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
33a34
> import static java.util.stream.ThowableHelper.checkNPE;
36c37
< * ExplodeOpTest
---
> * FlatMapOpTest
41c42,49
< public class ExplodeOpTest extends OpTestCase {
---
> public class FlatMapOpTest extends OpTestCase {
>
> public void testNullMapper() {
> checkNPE(() -> Stream.of(1).flatMap(null));
> checkNPE(() -> IntStream.of(1).flatMap(null));
> checkNPE(() -> LongStream.of(1).flatMap(null));
> checkNPE(() -> DoubleStream.of(1).flatMap(null));
> }
jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SummaryStatisticsTest.java
->
jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CollectAndSummaryStatisticsTest.java
2c2
< * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
---
> * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
24a25,26
> import org.testng.annotations.Test;
>
30a33,35
> import java.util.stream.DoubleStream;
> import java.util.stream.IntStream;
> import java.util.stream.LongStream;
33,34d37
< import org.testng.annotations.Test;
<
35a39
> import static java.util.stream.ThowableHelper.checkNPE;
38c42
< * TestSummaryStatistics
---
> * CollectAndSummaryStatisticsTest
43c47,84
< public class SummaryStatisticsTest extends OpTestCase {
---
> public class CollectAndSummaryStatisticsTest extends OpTestCase {
>
> public void testIntCollectNull() {
> checkNPE(() -> IntStream.of(1).collect(null,
> IntSummaryStatistics::accept,
> IntSummaryStatistics::combine));
> checkNPE(() -> IntStream.of(1).collect(IntSummaryStatistics::new,
> null,
> IntSummaryStatistics::combine));
> checkNPE(() -> IntStream.of(1).collect(IntSummaryStatistics::new,
> IntSummaryStatistics::accept,
> null));
> }
>
> public void testLongCollectNull() {
> checkNPE(() -> LongStream.of(1).collect(null,
> LongSummaryStatistics::accept,
> LongSummaryStatistics::combine));
> checkNPE(() -> LongStream.of(1).collect(LongSummaryStatistics::new,
> null,
> LongSummaryStatistics::combine));
> checkNPE(() -> LongStream.of(1).collect(LongSummaryStatistics::new,
> LongSummaryStatistics::accept,
> null));
> }
>
> public void testDoubleCollectNull() {
> checkNPE(() -> DoubleStream.of(1).collect(null,
> DoubleSummaryStatistics::accept,
> DoubleSummaryStatistics::combine));
> checkNPE(() -> DoubleStream.of(1).collect(DoubleSummaryStatistics::new,
> null,
> DoubleSummaryStatistics::combine));
> checkNPE(() -> DoubleStream.of(1).collect(DoubleSummaryStatistics::new,
> DoubleSummaryStatistics::accept,
> null));
> }
>
47a89,91
> instances.add(countTo(1000).stream().mapToInt(i -> i).collect(IntSummaryStatistics::new,
> IntSummaryStatistics::accept,
> IntSummaryStatistics::combine));
49a94,96
> instances.add(countTo(1000).parallelStream().mapToInt(i -> i).collect(IntSummaryStatistics::new,
> IntSummaryStatistics::accept,
> IntSummaryStatistics::combine));
53a101
> assertEquals(stats.getAverage(), (double) stats.getSum() / stats.getCount());
58a107
>
62a112,114
> instances.add(countTo(1000).stream().mapToLong(i -> i).collect(LongSummaryStatistics::new,
> LongSummaryStatistics::accept,
> LongSummaryStatistics::combine));
64a117,119
> instances.add(countTo(1000).parallelStream().mapToLong(i -> i).collect(LongSummaryStatistics::new,
> LongSummaryStatistics::accept,
> LongSummaryStatistics::combine));
68a124
> assertEquals(stats.getAverage(), (double) stats.getSum() / stats.getCount());
77a134,136
> instances.add(countTo(1000).stream().mapToDouble(i -> i).collect(DoubleSummaryStatistics::new,
> DoubleSummaryStatistics::accept,
> DoubleSummaryStatistics::combine));
79a139,141
> instances.add(countTo(1000).parallelStream().mapToDouble(i -> i).collect(DoubleSummaryStatistics::new,
> DoubleSummaryStatistics::accept,
> DoubleSummaryStatistics::combine));
83a146
> assertEquals(stats.getAverage(), stats.getSum() / stats.getCount());
More information about the core-libs-dev
mailing list