DoubleStream.count() overflow bug

Jan Beernink jan.beernink at
Tue Dec 24 14:56:49 PST 2013


I believe I may have discovered a small bug in the DoubleStream.count() operation. On JDK 8 b120, the following code will return -2147483648:

DoubleStream.generate(() -> 0.0)

I had a look at the code of and noticed that, although the return type is long, each element in the stream is (indirectly) mapped to an int of value 1 and then these ints are summed using IntStream.sum(). IntPipeline, LongPipeline and ReferencePipeline all count the number of elements in a similar way, but use longs instead of ints and correctly return 2147483648.


Jan Beernink

More information about the lambda-dev mailing list