harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Hindess" <mark.hind...@googlemail.com>
Subject [classlib][luni] java/util/HashMap.java bug waiting to happen?
Date Tue, 20 May 2008 11:51:07 GMT

While reviewing Aleksey's improvements in HARMONY-5791, I noticed the
following lines in HashMap.java (line 682):

    final void removeEntry(Entry<K, V> entry) {
        int index = entry.origKeyHash & (elementData.length - 1);
        Entry<K, V> m = elementData[index];
        if (m == entry) {
            elementData[index] = entry.next;
        } else {
[1]         while (m.next != entry && m.next != null) {
                m = m.next;
            }
[2]         m.next = entry.next;

        }
        modCount++;
        elementCount--;
    }

The while loop at [1] has two conditions.  The first relates to finding
the entry and the second relates to getting to the end of the linked
list (i.e. not finding the entry).  Executing the line [2] only really
makes sense if the first condition was met; if the second was met then
it might corrupt the list.

As it happens, the only caller of this method in HashMap.java does
ensure that the entry is present in the HashMap and thus in the linked
list but it still seems like a problem waiting to happen (or at the very
least a redundant condition on a while loop).

It isn't broken so I'm not sure what (if anything) to "fix".

Regards,
-Mark.



Mime
View raw message