Nulls

Remi Forax forax at univ-mlv.fr
Sun Sep 23 07:12:19 PDT 2012


On 09/23/2012 03:53 PM, Doug Lea wrote:
> On 09/23/12 09:34, Remi Forax wrote:
>> On 09/23/2012 03:12 PM, Doug Lea wrote:
>
>>> It encounters the same antipattern seen when you
>>> need to establish that a Map key has no mapping:
>>>  if (map.get(k) == null)     // don't know if there is a mapping
>>>     if (!map.containsKey(k)) // so recheck
>
>>
>> yes, for Map, we need a getEntry() but introducing it now as a 
>> default method
>> will have the same problem that the default implementation is not 
>> atomic.
>
> Mostly an aside: Without further guarantees, even getEntry
> encounters problems:
>   Map.Entry e = map.getEntry(k);
>   // ...
>   if (e.getValue() == null) // was e removed or is value null?
>
> In j.u.c ConcurrentMaps.entrySet().iterators, that return
> Entry objects, we guarantee snapshot semantics, which along with
> no-nulls rule, removes this uncertainty. Entry.setValue is
> still under-constrained though -- we do write-through, which
> revives an entry if had been removed.

I see, getEntry() will have create a new Entry to implement the snapshot 
semantics,
and allocating an object make getEntry() useless.

>
> -Doug
>
>

Rémi



More information about the lambda-libs-spec-observers mailing list