Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-839

[classlib][util]WeakHashMap(Map arg) throws NPE if arg.entrySet() returns null

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • None
    • None
    • Classlib
    • None
    • Windows XP
    • Novice

    Description

      VM + Classlib version 420749

      Problem:

      If we create a Map with entrySet() method that return null, WeakHashMap constructor with it won't throw NPE in RI but will in Harmony.

      Code to reproduce:

      import java.util.*;
      public class Test {
      public static void main (String[] args)

      { Map localMap = new TestMap(); new WeakHashMap(localMap); }


      }

      class TestMap implements Map {
      public void clear()

      { return; }
      public boolean containsKey(Object p0) { return false; }
      public boolean containsValue(Object p0) { return false; }
      public Set entrySet() { return null; }
      public boolean equals(Object p0) { return false; }
      public Object get(Object p0) { return null; }
      public int hashCode() { return 0; }
      public boolean isEmpty() { return false; }
      public Set keySet() { return null; }
      public Object put(Object p0, Object p1) { return null; }
      public void putAll(Map p0) { return; }

      public Object remove(Object p0)

      { return null; }
      public int size() { return 0; }
      public Collection values() { return null; }

      }

      Output in RI: none

      Output in Harmony:

      java.lang.NullPointerException
      at java.util.AbstractMap.putAll(AbstractMap.java:282)
      at java.util.WeakHashMap.<init>(WeakHashMap.java:231)
      at Test.main(Test.java:5)

      Please see the unit test for this issue + patch to fix it attached

      Attachments

        1. patch.txt
          3 kB
          Anton Luht
        2. identity_hash_map_patch.txt
          2 kB
          Anton Luht
        3. harmony-839.diff
          10 kB
          spark shen

        Activity

          People

            paulex Paulex Yang
            aluht Anton Luht
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: