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

Implementation requirements code example for ConcurrentMap.putIfAbsent() returns incorrect value

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      The description of both ConcurrentMap.computeIfAbsent and Map.computeIfAbsent state that the return value is the current (existing or computed) value mapped for the given key.

      However, the "equivalent code" snippet in the Implementation Requirements section:
       if (map.get(key) == null) {
           V newValue = mappingFunction.apply(key);
           if (newValue != null)
               return map.putIfAbsent(key, newValue);
       }

      Shows it returning the result of putIfAbsent(), which is defined to return the previous mapping, or null if none existed.



      URL OF FAULTY DOCUMENTATION :
      https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentMap.html#computeIfAbsent-K-java.util.function.Function-

            aroy Abhijit Roy (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: