DoubleStream.count() overflow bug
Jan Beernink
jan.beernink at gmail.com
Tue Dec 24 14:56:49 PST 2013
Hi,
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)
.limit(2147483648L)
.count()
I had a look at the code of java.util.stream.DoublePipeline.count() 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.
Regards,
Jan Beernink
More information about the lambda-dev
mailing list