Javadoc of Int/Long/DoubleSummaryStatistics should mention possible overflow of count

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 14
    • Affects Version/s: None
    • Component/s: core-libs
    • b04

      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}

            Assignee:
            Ivan Gerasimov
            Reporter:
            Ivan Gerasimov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: