-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
beta3
-
generic
-
generic
-
Verified
Name: ddT132432 Date: 09/17/2001
java version "1.4.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)
The general contract of Map.equals() does not permit throwing a
NullPointerException; it simply permits returning true or false. However, this
simple program demonstrates that AbstractMap simply delegates to Map.get(),
which can throw a NullPointerException in the case of Hashtable, where null keys
are not permitted. Therefore, AbstractMap is flawed, and needs to trap any
exceptions and return false in such a case.
import java.util.*;
class Foo {
public static void main(String[] args) {
Map m = new HashMap();
m.put(null, "");
Map h = new Hashtable();
h.put("", "");
m.equals(h);
}
}
$ java Foo
Exception in thread "main" java.lang.NullPointerException
at java.util.Hashtable.get(Hashtable.java:321)
at java.util.AbstractMap.equals(AbstractMap.java:519)
at Foo.main(Foo.java:8)
(Review ID: 132020)
======================================================================