Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8020146 JCK issues for java.util.stream
  3. JDK-8020001

TreeMap().values().stream().substream().parallel().iterator() returns not the expected elements

XMLWordPrintable

      Consider the following code:

               Stream<String> stream = new TreeMap<String, String>() {{
                  put("c", "c");
                  put("d", "d");
                  put("b", "b");
                  put("a", "a");
              }}.values().stream();

              Stream parallel = (Stream)stream.substream(1).parallel();
              Iterator iterator = parallel.iterator();
              System.out.println("next = " + iterator.next());
              System.out.println("next = " + iterator.next());
              System.out.println("next = " + iterator.next());
              System.out.println("next = " + iterator.next());


      The output will be

      next = a
      next = b
      next = c
      Exception in thread "main" java.util.NoSuchElementException
      at java.util.Spliterators$1Adapter.next(Spliterators.java:688)

      Which is not expected according to the specification of method Stream.substream():

           * Returns a stream consisting of the remaining elements of this stream
           * after indexing {@code startInclusive} elements into the stream.


      The following JCK tests will fail due to this issue:

      api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapValueStream[checkSubstream]
      api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapValueStream[checkSubstream2]api/java_util/TreeMap/ValuesStream.html#ValuesStream[checkSubstream]
      api/java_util/TreeMap/ValuesStream.html#ValuesStream[checkSubstream2]
      api/java_util/TreeMap/ValuesParallelStream.html#ValuesParallelStream[checkSubstream]
      api/java_util/TreeMap/ValuesParallelStream.html#ValuesParallelStream[checkSubstream2]



            psandoz Paul Sandoz
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: