On Mon, 2011-10-24 at 10:11 +0300, Pekka Enberg wrote:
> Looking at the code, it's obviously broken for HashMap.put() with a null key.

Urgh yes.

> @@ -345,7 +345,10 @@ public class HashMap<K, V> extends AbstractMap<K, V>
>  
>      while (e != null)
>        {
> -        if ((key.hashCode() == e.key.hashCode()) && equals(key, e.key))
> +        int hash1 = key == null ? 0 : key.hashCode();
> +        int hash2 = e.key == null ? 0 : e.key.hashCode();
> +
> +        if ((hash1 == hash2) && equals(key, e.key))
>            {
>              e.access(); // Must call this for bookkeeping in LinkedHashMap.
>              V r = e.value;

Are you sure that is right?
What about a key which isn't null but has a hashCode() of zero?

Thanks,

Mark

Reply via email to