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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P4
    • Resolution: Won't Fix
    • 8u31
    • None
    • core-libs

    Description

      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 ----------

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: