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

Documentation error for java.util.concurrent.ConcurrentMap#computeIfAbsent

XMLWordPrintable

      FULL PRODUCT VERSION :
      1.8.0_102

      ADDITIONAL OS VERSION INFORMATION :
      Not OS related

      A DESCRIPTION OF THE PROBLEM :
      The documentation of java.util.concurrent.ConcurrentMap#computeIfAbsent contains a snippet of code:

      if (map.get(key) == null) {
           V newValue = mappingFunction.apply(key);
           if (newValue != null)
               return map.putIfAbsent(key, newValue);
       }

      This is contradictory with the return information that says:
      returns the current (existing or computed) value associated with the specified key, or null if the computed value is null

      putIfAbsent returns the previous value of the map, not the new one.
      The snipped is incorrect because the implementation returns the new value not the old one.


      REPRODUCIBILITY :
      This bug can be reproduced always.

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: