Request for review: 6312706: Map entrySet iterators should return different entries on each call to next()
neil.richards at ngmr.net
Wed Mar 30 16:07:15 UTC 2011
On Tue, 2011-03-29 at 15:09 -0700, Mike Duigou wrote:
> I think your suspicion is correct that the anonymous inner Object is
> used rather than new Object so that it can be distinguished more
> easily in heap dumps or via other tools. I would be fine with using
> Integer(0) as the sentinel value. I've always used new
> String("something useful") rather than new Object for sentinel values.
> Neil, do you have a strong reason or preference for using an anonymous inner Object?
Hi Jason, thanks for your review and suggestion.
My intent in changing NULL here was merely to avoid having to have a
conditional check for a value of NULL in hashCode().
It looks like the NULL value object is only checked for and compared by
identity, so I think its requirements are that:
1. It is a unique object. (ie. It is not the same object as any
that might be stored as a "legitimate" value).
2. It returns a hashCode of 0. (This follows the convention that
'null' - or objects that represent it - have a hashCode of 0).
So, having the NULL object set to 'new Integer(0)' would work, whilst
(for example) having it set to 'Integer.valueOf(0)' would not.
(The other conversation you referred to is specifically about using
distinct classes for objects used for synchronization, so that
deadlock / contention analysis tools can produce results which can be
interpreted without also needing to analyse associated heap dumps, in a
tool like the Eclipse Memory Analyzer , to work out which object
(type) is holding contended / deadlocked "lock" objects.
As the NULL object here is not used for synchronization, that argument
does not apply to this object).
In summary, as using 'new Integer(0)' for NULL would save on having an
extra Class definition, I'm all in favour of adopting your amendment -
thanks once again.
Mike, are you happy to make this simple modification to the changeset,
or shall I send you an updated version ?
Unless stated above:
IBM email: neil_richards at uk.ibm.com
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
More information about the core-libs-dev