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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 8u31
    • 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 ----------

            psandoz Paul Sandoz
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: