RFR 8005704: Update ConcurrentHashMap to v8

Martin Buchholz martinrb at google.com
Tue May 28 19:53:36 UTC 2013


Vaguely related, looking at Map.getOrDefault:

---

Whitspace is wonky - we want more whitespace before the '*', less after.

    /**
    *  Returns the value to which the specified key is mapped,
    *  or {@code defaultValue} if this map contains no mapping
    *  for the key.

---

The @param for defaultValue is missing.

---
Isn't the following paragraph a leading candidate for one of those
newfangled javadoc tags y'all've been creating, so that inheritDoc doesn't
snag it?

    * <p>The default implementation makes no guarantees about
synchronization
    * or atomicity properties of this method. Any implementation providing
    * atomicity guarantees must override this method and document its
    * concurrency properties.

---

ObConcurrentHashMap:
The javadoc for other getOrDefault methods should be sync'ed with Map's.
I like:

--- src/main/java/util/concurrent/ConcurrentHashMap.java 24 May 2013
03:27:47 -0000 1.216
+++ src/main/java/util/concurrent/ConcurrentHashMap.java 28 May 2013
19:49:22 -0000
@@ -2596,13 +2596,13 @@
     }

     /**
-     * Returns the value to which the specified key is mapped,
-     * or the given defaultValue if this map contains no mapping for the
key.
+     * Returns the value to which the specified key is mapped, or the
+     * given default value if this map contains no mapping for the key.
      *
-     * @param key the key
+     * @param key the key whose associated value is to be returned
      * @param defaultValue the value to return if this map contains
      * no mapping for the given key
-     * @return the mapping for the key, if present; else the defaultValue
+     * @return the mapping for the key, if present; else the default value
      * @throws NullPointerException if the specified key is null
      */
     public V getOrDefault(Object key, V defaultValue) {
--- src/main/java/util/concurrent/ConcurrentSkipListMap.java 7 May 2013
20:25:36 -0000 1.123
+++ src/main/java/util/concurrent/ConcurrentSkipListMap.java 28 May 2013
19:49:22 -0000
@@ -1513,13 +1513,13 @@
     }

     /**
-     * Returns the value to which the specified key is mapped,
-     * or the given defaultValue if this map contains no mapping for the
key.
+     * Returns the value to which the specified key is mapped, or the
+     * given default value if this map contains no mapping for the key.
      *
-     * @param key the key
+     * @param key the key whose associated value is to be returned
      * @param defaultValue the value to return if this map contains
      * no mapping for the given key
-     * @return the mapping for the key, if present; else the defaultValue
+     * @return the mapping for the key, if present; else the default value
      * @throws NullPointerException if the specified key is null
      * @since 1.8
      */


---

Is atomicity part of the contract of ConcurrentMap.getOrDefault?
 Currently, it doesn't say.
Actually, there are two possible guarantees it could make - whether the
default implementation ConcurrentMap.getOrDefault is atomic (when the map
does not accept nulls) and whether subclasses that override getOrDefault
must make this guarantee.

---

Curiously, ConcurrentMap doesn't guarantee that get() is atomic.  Perhaps
it should?

---



More information about the core-libs-dev mailing list