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

DoubleStream.count is incorrect for a stream containing > Integer.MAX_VALUE elements

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: 8, 9
    • Fix Version/s: 9
    • Component/s: core-libs

      Backports

        Description

        The code for the DoubleStream.count method is incorrect:

            public final long count() {
                return mapToObj(e -> null).mapToInt(e -> 1).sum();
            }

        If a a double stream contains more than Integer.MAX_VALUE then the sum will overflow resulting in an incorrect value. The code should be:

            public final long count() {
                return mapToLong(e -> 1).sum();
            }

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved: