The javadoc has this sentance:
"""
This implementation does not check for overflow of the sum.
"""
It need to mention that overflow of the count is also possible.
While it would take long time to hit the overflow via calling the accept(x) method, it can still be easily caused by combining instances of SummaryStatistics:
public class T {
static public void main(String[] args) {
var stat = new IntSummaryStatistics(1, 1, 1, 1);
for (int i = 0; i < 65; ++i) {
System.out.println(stat);
stat.combine(stat);
}
}
}
IntSummaryStatistics{count=1, sum=1, min=1, average=1.000000, max=1}
IntSummaryStatistics{count=2, sum=2, min=1, average=1.000000, max=1}
....
IntSummaryStatistics{count=2305843009213693952, sum=2305843009213693952, min=1, average=1.000000, max=1}
IntSummaryStatistics{count=4611686018427387904, sum=4611686018427387904, min=1, average=1.000000, max=1}
IntSummaryStatistics{count=-9223372036854775808, sum=-9223372036854775808, min=1, average=0.000000, max=1}
IntSummaryStatistics{count=0, sum=0, min=1, average=0.000000, max=1}
"""
This implementation does not check for overflow of the sum.
"""
It need to mention that overflow of the count is also possible.
While it would take long time to hit the overflow via calling the accept(x) method, it can still be easily caused by combining instances of SummaryStatistics:
public class T {
static public void main(String[] args) {
var stat = new IntSummaryStatistics(1, 1, 1, 1);
for (int i = 0; i < 65; ++i) {
System.out.println(stat);
stat.combine(stat);
}
}
}
IntSummaryStatistics{count=1, sum=1, min=1, average=1.000000, max=1}
IntSummaryStatistics{count=2, sum=2, min=1, average=1.000000, max=1}
....
IntSummaryStatistics{count=2305843009213693952, sum=2305843009213693952, min=1, average=1.000000, max=1}
IntSummaryStatistics{count=4611686018427387904, sum=4611686018427387904, min=1, average=1.000000, max=1}
IntSummaryStatistics{count=-9223372036854775808, sum=-9223372036854775808, min=1, average=0.000000, max=1}
IntSummaryStatistics{count=0, sum=0, min=1, average=0.000000, max=1}
- csr for
-
JDK-8226784 Javadoc of Int/Long/DoubleSummaryStatistics should mention possible overflow of count
-
- Closed
-
- links to