RFR: 8029055: Map.merge must refuse null values
Martin Buchholz
martinrb at google.com
Tue Nov 26 18:39:58 UTC 2013
On Tue, Nov 26, 2013 at 5:35 AM, Stephen Colebourne <scolebourne at joda.org>wrote:
> See the new thread for the general Javadoc issues. I'll focus on null here.
>
> Given a map {"Key" -> null} I find the notion that putIfAbsent() or
> computeIfAbsent() ignore the existing mapping just plain wrong. While
> I can rationalise it (just) it is a horrible reworking of the meaning
> of "absent".
>
> Similarly, for "computeIfPresent()", my expectation is that the
> mapping is present, and that the null should be an input to the
> function.
>
This is also very much my expectation for computeIfPresent. I can see why
the current semantics may have been chosen, because the obvious
implementation choice needs just one call to map.get without a call to
map.containsKey. But it seems OK to disambiguate using containsKey when
get returns null. Concurrent maps don't have problems implementing this
either way because they don't allow nulls.
More information about the core-libs-dev
mailing list