IntStream/LongStream: sum() must throw ArithmeticException if overflow occurs

XMLWordPrintable

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: P4
    • None
    • Affects Version/s: 8u31
    • Component/s: core-libs

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      The "sum()" method in the classes IntStream/LongStream (of the package java.util.stream) must throw an ArithmeticException if overflow occurs.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An ArithmeticException is thrown.
      ACTUAL -
      Overflow occurs and a negative result is printed.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.stream.IntStream;

      class IntStreamSum {

      public static void main(String[] args) {
      System.out.println(IntStream.range(1, 65537).sum());
      }

      }

      ---------- END SOURCE ----------

            Assignee:
            Paul Sandoz
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: