Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8224716

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

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P4
    • Resolution: Fixed
    • None
    • 14
    • core-libs
    • b04

    Description

      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}

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: