Hi Kasper,

Sorry for the *very* late reply, i forgot about this, but was reminded when 
trawling through some bugs.

On Apr 17, 2014, at 3:13 PM, Kasper Nielsen <kaspe...@gmail.com> wrote:

> Hi,
> 
> I'm trying to build a small test suite for for a custom stream
> implementation I'm making.
> And I found a couple of small issues with java.util.stream.Stream. Nothing
> major but might be worth fixing
> 
> 1)
> There are couple of places where null checks are missing
> 
> *Stream.close
> Int/Double/LongStream.flatmap
> Int/Double/LongStream.collect(x,y, 3rd) 3rd argument not being checked
> 
> 
> 2)
> These methods does throw NPE but they consume the stream before throwing.
> I like to think of null parameter checks as side-effect free.
> 
> Stream.forEach
> Stream.forEachOrdered
> Stream.sorted
> Stream.toArray
> 

I see you logged a bug (thanks for doing that):

  https://bugs.openjdk.java.net/browse/JDK-8044047

For 1) I presume you mean BaseStream.onClose rather than BaseStream.close?

For 2) i am not sure it is worth enforcing, specification-wise. It's hard to 
envisage how a client would recover and reuse the stream in such scenarios, and 
even if it were the case it seems a very minor one. Currently the 
implementation is free to consolidate checks, even if there are side-effects 
before those checks occur.


> 3)
> LongStream.Average does not always work as intended with high long values
> 
> Arrays.*asList*(Long.*MAX_VALUE* - 1000L, Long.*MAX_VALUE* -
> 1000L).stream().mapToLong(e -> e).average().getAsDouble; return -1001.0
> 
> Same thing with SummaryStatistics
> 

Right, we don't check for overflow of the sum. That is stated on the 
*SummaryStatistics class docs, but not in the Int/LongStream.sum/average 
method. I think we should add an @implNote to those methods.

Paul.

Reply via email to