Mo DeJong wrote,
> There seems to be a really serious bug in the 
> System.identityHashCode() method in all > JDK 1.2 releases 
> derived from Sun code. The problem only shows up in "high 
> load" situations. Basically, two different Java objects of 
> the same class can return the exact same unique id from the 
> System.identityHashCode() method.

Why is this a bug? The only requirement on a hashCode (system
or otherwise) is that two == or .equal() objects should have 
the same hashCode. There's no requirement that != or !.equal()
objects should have different hashCodes.

Apart from anything else, hashCodes are ints, so there are at
most 2^32 distinct ones. A 64 bit implementation could support 
more that 2^32 objects, in which case there'd have to be some collisions.

> So far, I have identified a couple of workarounds. I could 
> just require that everyone use a JDK 1.1 release. I could 
> also require that people use Kaffe (it does not have the 
> bug). The final option would be to write my own UID() method 
> that would try to do something to detect a duplicate id and 
> generate a unique one.
>
> Comments anyone?

You shouldn't expect System.identityHashCode() to be usable as
a UID. Assuming otherwise is non-portable ... as you've just
discovered.

Cheers,


Miles

-- 
Miles Sabin                       Cromwell Media
Internet Systems Architect        5/6 Glenthorne Mews
+44 (0)20 8817 4030               London, W6 0LJ, England
[EMAIL PROTECTED]          http://www.cromwellmedia.com/


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to