Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4104150

HashMap.put throws NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.0
    • 1.2.0
    • core-libs
    • 1.2beta3
    • x86
    • windows_95
    • Not verified



      Name: dgC58589 Date: 01/15/98


      HashMap's documentation claims that is handles
      null values (and indeed the code appears to
      be written to), but the put method checks for
      value==null and throws a NullPointerException;
      this code demonstrates...

      Excerpt from javadoc :

      Hash-table based implementation of the Map interface. This implementation provides all of the optional Map
      operations, and permits null values but not the null key. (HashMap is roughly equivalent to Hashtable, except that
      it is unsynchronized and permits null values.) This class makes no guarantees as to the order of the Map; in
      particular, it does not guarantee that the order will remain constant over time.

      Test code:

      import java.util.Map;
      import java.util.HashMap;

      class HashMapBug {
          public static void main(String args[]) {
              Map map = new HashMap();

              map.put("bug", null);
              Object o = map.get("bug");
          }
      }


      (Review ID: 23313)
      ======================================================================

            jjb Josh Bloch (Inactive)
            dgrahamcsunw David Graham-cumming (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: