RFR: 7057785 : (xs) Add note to hashCode() that support for self referential is optional

Tom Hawtin tom.hawtin at oracle.com
Thu Aug 29 13:30:19 UTC 2013

On 29/08/2013 00:23, Mike Duigou wrote:

> I am unsure what solution was used in Common Lisp (I think I knew once). The most likely solution for Java Collections would be to use a ThreadLocal<Boolean> which potentially recursive methods could check/set on entry and avoid recursing. Explicitly concurrent hostile implementations could use a plain boolean field rather than a ThreadLocal.

There are many problems with that, as you'd expect with anything 
involving ThreadLocal. Any use of threads (say the new 
Spliterable-related stuff) is going to have surprising behaviour. 
Callers have to be aware of global state, so may get incorrect answers 
(perhaps okay for logging, not so good for hashtables).

The problem is the APIs. Fiddling with internal implementation will just 
end in "cleverness".


More information about the core-libs-dev mailing list