This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Hashtable contains/remove and null


Hi,

This makes sure that we always throw a NullPointerException when we see
a null key in Hashtable. This fixes a couple of Mauve failures.

2002-04-07  Mark Wielaard <mark@klomp.org>

    * java/util/Hashtable.java (contains): Remove NullPointer check.
    (containsValue): Add NullPointer check.
    (remove): Always throw NullPointerException when key is null.

OK for mainline/branch?

Cheers,

Mark
Index: java/util/Hashtable.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/Hashtable.java,v
retrieving revision 1.16
diff -u -r1.16 Hashtable.java
--- java/util/Hashtable.java	22 Jan 2002 22:40:38 -0000	1.16
+++ java/util/Hashtable.java	7 Apr 2002 10:06:59 -0000
@@ -322,10 +322,6 @@
    * <code>containsValue()</code>, and is O(n).
    * <p>
    *
-   * Note: this is one of the <i>old</i> 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 <code>value</code> is null
@@ -334,25 +330,27 @@
    */
   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 <code>o</code>, such that
    * <code>o.equals(value)</code>. This is the new API for the old
-   * <code>contains()</code>, except that it is forgiving of null.
+   * <code>contains()</code>.
    *
    * @param value the value to search for in this Hashtable
    * @return true if at least one key maps to the value
+   * @throws NullPointerException if <code>value</code> is null
    * @see #contains(Object)
    * @see #containsKey(Object)
    * @since 1.2
    */
   public boolean containsValue(Object value)
   {
+    // Check if value is null.
+    if (value == null)
+      throw new NullPointerException();
+
     for (int i = buckets.length - 1; i >= 0; i--)
       {
         HashEntry e = buckets[i];
@@ -468,17 +466,12 @@
    * 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 <code>null</code> is returned.
-   * <b>NOTE:</b>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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]