Re: Non-Deterministic / Unpredictable Behavior (Again) [SOLVED]

Randall R Schulz <[email protected]> Sat, 12 Apr 2008 07:12:50 -0700
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
On Friday 11 April 2008 22:37, Ken Gentle wrote:
> At the risk of making clear why I lurk more than participate, why did
> not overriding hashcode in this instance (where the default equals is
> used) introduce non-deterministic behavior?

The default hashCode() uses the JVM analog to the object's address (not
really the virtual address of its storage, which can change during GC,
but what Mac programmers in the good old days would have called
a "handle"). Because of things like the GC thread and other
unpredictable and variable circumstances from one invocation to the
next (and, perhaps, because of the newer JRE's ability to share
bytecodes between different instances of the JRE, the activity of other
Java programs on the same host??), objects do not get the same
identifier on every run. This is true even if your program issues
precisely the same sequence of calls to constructors. Thus they bear
different hash codes and when stored hashed structures produce
different iteration orders.


> Congrats on finding the issue - these types of problems are
> particularly satisfying to solve, aren't they?

I'm happy. It took long enough.


> Ken

Randall Schulz

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com