hg: lambda/lambda/jdk: Change Map.putIfAbsent() to treat null values as absent.
Peter Levart
peter.levart at gmail.com
Thu Mar 28 08:44:22 PDT 2013
Hi Mike,
I think Map.putIfAbsent is better now, together with other default
methods that depend on it, which can now be atomic if putIfAbsent is
atomic, so transitively all new methods can be enforced by specification
to be atomic on ConcurrentMap. This, I think, is a desirable property of
ConcurrentMap specification.
One method stands out: Map.getOrDefault(key, defaultValue).
This is new method, which means that not all ConcurrentMap
implementations have it redefined with atomicity in mind. Currently the
following call:
concurrentMap.getOrDefault(key, nonNullValue)
can return null even though there was no such mapping (key -> null)
present in the map at any time. The specification could be changed (like
for putIfAbsent):
485 /**
486 * Returns the non-null value to which the specified key
is mapped,
487 * or {@code defaultValue} if the key is mapped to null
or this map
488 * contains no mapping for the key
What do you think?
Regards, Peter
On 03/27/2013 03:58 PM, mike.duigou at oracle.com wrote:
> Changeset: f5b67786b6c9
> Author: mduigou
> Date: 2013-03-26 22:33 -0700
> URL: http://hg.openjdk.java.net/lambda/lambda/jdk/rev/f5b67786b6c9
>
> Change Map.putIfAbsent() to treat null values as absent.
>
> ! src/share/classes/java/util/HashMap.java
> ! src/share/classes/java/util/Map.java
> ! test/java/util/Map/Defaults.java
>
>
More information about the lambda-dev
mailing list