Non-terminating Stream.flatMap() with short-circuiting downstream operation

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 8u45
    • Component/s: core-libs

      FULL PRODUCT VERSION :
      java version "1.8.0_25"
      Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      While the following works as expected, printing out the infinite sequence of integers

      Stream.of("").flatMap(x -> Stream.iterate(1, i -> i + 1)).forEach(System.out::println);

      the following code prints out only the "1", but still does not terminate:

      Stream.of("").flatMap(x -> Stream.iterate(1, i -> i + 1)).limit(1).forEach(System.out::println);

      This may have the same cause as Bug JDK-8075939 (flatMap does not do a cancellation check on the stream), but to my eyes the effect is even stranger.


      REPRODUCIBILITY :
      This bug can be reproduced always.

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

              Created:
              Updated:
              Resolved: