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

Stream.concat behaves like terminal operation

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b34
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Not verified

      Description

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      MacOS Sierra

      A DESCRIPTION OF THE PROBLEM :
      Below is the code, if you uncomment Stream.concat then you will see that stream supplier has been called, but it should not happen because concat is not a terminal operation

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try the code fragment

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Stream.concat should behave as intermediate operation, stream supplier should not be called
      ACTUAL -
      I see that both streams are being initialized even without stream usage

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      @Test
          public void testConcat() {

              Stream<Integer> stream = createLazyStream();
              // Stream<Integer> result = Stream.concat(stream, createLazyStream());

          }

          private Stream<Integer> createLazyStream() {
              return StreamSupport.stream(() -> {

                  System.out.println("initializing stream");
                  return IntStream.range(1,10).spliterator();

              }, Spliterator.ORDERED, false);
          }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psandoz Paul Sandoz (Inactive)
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: