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

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

    Details

      Description

      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-

        Issue Links

          Activity

          Hide
          psonal Pallavi Sonal added a comment -
          This issue with the documentation has been fixed in JDK 9 with JDK-8145164.
          Show
          psonal Pallavi Sonal added a comment - This issue with the documentation has been fixed in JDK 9 with JDK-8145164 .

            People

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

              Dates

              • Created:
                Updated:
                Resolved: