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

TreeMap().values().stream().distinct().parallel().iterator() does not preserve the sorted order of elements

XMLWordPrintable

      Consider the following code sample:

              Stream<Double> stream = new TreeMap<Double, Double>() {{
                  put(41.0, 41.0);
                  put(10.0, 10.0);
                  put(33.0, 33.0);
                  put(22.0, 22.0);
              }}.values().stream();

              Stream parallel = (Stream)stream.distinct().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());
              System.out.println("next = " + iterator.next());



      The output is not perfectly expected as the ascending order is not present:

      next = 22.0
      next = 41.0
      next = 33.0
      next = 10.0
      Exception in thread "main" java.util.NoSuchElementException
      at java.util.Spliterators$1Adapter.next(Spliterators.java:688)


      The following JCK tests will fail due to this:

      api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapValueParallelStream[checkDistinct]
      api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapValueStream[checkDistinct]
      api/java_util/TreeMap/ValuesStream.html#ValuesStream[checkDistinct]
      api/java_util/TreeMap/ValuesParallelStream.html#ValuesParallelStream[checkDistinct]
      api/java_util/Collections/synchronizd/index.html#SynchronizedSortedMapValueStream[checkDistinct]
      api/java_util/Collections/synchronizd/index.html#SynchronizedSortedMapValueParallelStream[checkDistinct]


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

              Created:
              Updated:
              Resolved: