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

b106-lambda: j.u.Map.merge doesn't work as specified if contains key:null pair

    XMLWordPrintable

Details

    Description

      Specification

      http://download.java.net/jdk8/docs/api/java/util/Map.html#merge%28K,%20V,%20java.util.function.BiFunction%29

      states:

      "If the specified key is not already associated with a value or is associated with null, associates it with the given value."

      The implementation behavior of JDK8-LAMBDA (probably starting from b106) contradicts the spec in case if the given key is associated with "null"

      Consider the following code sample:

      -------------------------------
              final HashMap map = new HashMap();
              map.put("a", null);
              System.out.println("result = " + map.merge("a", "new", (v1, v2) -> "merged"));
      -------------------------------

      JDK8b106-lambda:

      result = merged

      on JDK8b106:

      result = new


      The following JCK tests fail due to this:
      api/java_util/Collections/checked/CheckedMap8Tests.html#CheckedMap8Tests[merge_nullKeyValue_noNPE]
      api/java_util/Collections/checked/CheckedMap8Tests.html#CheckedMap8Tests[merge_nullKey_noNPE]
      api/java_util/Collections/synchronizd/SynchronizedMap8Tests.html#SynchronizedMap8Tests[merge_nullKeyValue_noNPE]
      api/java_util/Collections/synchronizd/SynchronizedMap8Tests.html#SynchronizedMap8Tests[merge_nullKey_noNPE]
      api/java_util/HashMap/Map8Tests.html#Map8Tests[merge_nullKeyValue_noNPE]
      api/java_util/HashMap/Map8Tests.html#Map8Tests[merge_nullKey_noNPE]
      api/java_util/LinkedHashMap/Map8Tests.html#Map8Tests[merge_nullKeyValue_noNPE]
      api/java_util/LinkedHashMap/Map8Tests.html#Map8Tests[merge_nullKey_noNPE]
      api/java_util/Collections/checked/CheckedMap8Tests.html#CheckedMap8Tests[merge_presentKey_mappedToNull_newValue]
      api/java_util/Collections/synchronizd/SynchronizedMap8Tests.html#SynchronizedMap8Tests[merge_presentKey_mappedToNull_newValue]
      api/java_util/HashMap/Map8Tests.html#Map8Tests[merge_presentKey_mappedToNull_newValue]
      api/java_util/LinkedHashMap/Map8Tests.html#Map8Tests[merge_presentKey_mappedToNull_newValue]

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: