diff --git a/classpath/java/util/HashMap.java b/classpath/java/util/HashMap.java index 9f8c3bec1f..8892699358 100644 --- a/classpath/java/util/HashMap.java +++ b/classpath/java/util/HashMap.java @@ -136,7 +136,6 @@ public class HashMap implements Map { if (c == null) { insert(helper.make(key, value, null)); } else { - V old = c.getValue(); c.setValue(value); } return c; @@ -180,8 +179,15 @@ public class HashMap implements Map { } public V put(K key, V value) { - Cell c = putCell(key, value); - return (c == null ? null : c.getValue()); + Cell c = find(key); + if (c == null) { + insert(helper.make(key, value, null)); + return null; + } else { + V old = c.getValue(); + c.setValue(value); + return old; + } } public void putAll(Map elts) {