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

Stream created from Map.Entries of Cs.checkedMap(..) and Cs.unmodifiableMap(..) returns not the same elements as iterator over the same map entries

XMLWordPrintable

      Consider the following code:

      --------------

              final HashMap<String, String> hashMap = new HashMap<>();
              hashMap.put("a", "b");
              final Set<Map.Entry<String, String>> set = Collections.checkedMap(hashMap, String.class, String.class).entrySet();
      // final Set<Map.Entry<String, String>> set = Collections.unmodifiableMap(hashMap).entrySet();

              Map.Entry<String, String> e1 = set.iterator().next();
              Map.Entry<String, String> e2 = set.stream().findFirst().get();

              System.err.println("same instances? " + (e1 == e2));

      -----------------

      The output will be:

      same instances? false

      The following JCK tests fail due to this issue:


      api/java_util/Collections/checked/index.html#CheckedMapEntrySetStream
      api/java_util/Collections/checked/index.html#CheckedMapEntrySetParallelStream
      api/java_util/Collections/checked/index.html#CheckedSortedMapEntrySetParallelStream
      api/java_util/Collections/checked/index.html#CheckedSortedMapEntrySetStream
      api/java_util/Collections/unmodifiable/index.html#UnmodifiableMapEntrySetStream
      api/java_util/Collections/unmodifiable/index.html#UnmodifiableMapEntrySetParallelStream
      api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapEntrySetParallelStream
      api/java_util/Collections/unmodifiable/index.html#UnmodifiableSortedMapEntrySetStream



            mduigou Mike Duigou
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: