From 0dccd146bad89577c353fbad71080bfd75c27f03 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 7 Apr 2002 12:18:58 +0000 Subject: Hashtable.java (contains): Remove NullPointer check. * java/util/Hashtable.java (contains): Remove NullPointer check. (containsValue): Add NullPointer check. (remove): Always throw NullPointerException when key is null. From-SVN: r51994 --- libjava/java/util/Hashtable.java | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'libjava/java') diff --git a/libjava/java/util/Hashtable.java b/libjava/java/util/Hashtable.java index 65759e7..71ec4b80 100644 --- a/libjava/java/util/Hashtable.java +++ b/libjava/java/util/Hashtable.java @@ -322,10 +322,6 @@ public class Hashtable extends Dictionary * containsValue(), and is O(n). *

* - * Note: this is one of the old Hashtable methods which does - * not like null values; it throws NullPointerException if the - * supplied parameter is null. - * * @param value the value to search for in this Hashtable * @return true if at least one key maps to the value * @throws NullPointerException if value is null @@ -334,19 +330,17 @@ public class Hashtable extends Dictionary */ public synchronized boolean contains(Object value) { - // Check if value is null. - if (value == null) - throw new NullPointerException(); return containsValue(value); } /** * Returns true if this Hashtable contains a value o, such that * o.equals(value). This is the new API for the old - * contains(), except that it is forgiving of null. + * contains(). * * @param value the value to search for in this Hashtable * @return true if at least one key maps to the value + * @throws NullPointerException if value is null * @see #contains(Object) * @see #containsKey(Object) * @since 1.2 @@ -358,11 +352,16 @@ public class Hashtable extends Dictionary HashEntry e = buckets[i]; while (e != null) { - if (AbstractCollection.equals(value, e.value)) + if (value.equals(e.value)) return true; e = e.next; } } + + // Must throw on null argument even if the table is empty + if (value == null) + throw new NullPointerException(); + return false; } @@ -468,17 +467,12 @@ public class Hashtable extends Dictionary * Removes from the table and returns the value which is mapped by the * supplied key. If the key maps to nothing, then the table remains * unchanged, and null is returned. - * NOTE:Map.remove and Dictionary.remove disagree whether null - * is a valid parameter; at the moment, this implementation obeys Map.remove, - * and silently ignores null. * * @param key the key used to locate the value to remove * @return whatever the key mapped to, if present */ public synchronized Object remove(Object key) { - if (key == null) - return null; int idx = hash(key); HashEntry e = buckets[idx]; HashEntry last = null; -- cgit v1.1