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

TreeMap().values().parallelStream().limit().toArray() does not return the expected elements

XMLWordPrintable

      Consider the following code:

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

              Stream limit = (Stream)stream.limit(3);
              Object[] objects = limit.toArray();
              System.out.println(Arrays.toString(objects));


      The output will be unexpected:

      [b, c, d]

      Issue is reproduced with different sets of data.

      The following JCK tests will fail:

      api/java_util/TreeMap/ValuesParallelStream.html#ValuesParallelStream[checkLimit]
      api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapValueParallelStream[checkLimit]
      api/java_util/Collections/synchronizd/index.html#SynchronizedSortedMapValueParallelStream[checkLimit]



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

              Created:
              Updated:
              Resolved: