Bug(s) inside IdentityHashMap.java

Tom Tromey tromey@redhat.com
Thu Sep 27 08:05:00 GMT 2001


>>>>> "Martin" == Martin Kahlert <martin.kahlert@infineon.com> writes:

Martin> I have some problems with IdentityHashMap.java:
Martin> First: Where is table.length set?
`table' is an array. `table.length' is set when the array is created.
Martin> The file contains a lot of copies of the term 
Martin> h = Math.abs (2 * System.identityHashCode (key) % table.length);
Martin> this is the same as 
Martin> h = Math.abs ((2 * System.identityHashCode (key)) % table.length);
Martin> thus, h may be table.length - 1;
Martin> but in get() we ask for return table[h + 1]; 
Martin> which is an memory violation.
Of course. Sorry about this. I'll write a test suite for
IdentityHashMap soon -- something I should have done on day 1.
Meanwhile I think we really need:
 h = Math.abs (2 * (System.identityHashCode (key) % (table.length / 2)));
Conceptually table is an array of length L where each entry is a
key/value pair. We want to compute the index based on the conceptual
length, and then double that.
Tom


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /