Harmony
  1. Harmony
  2. HARMONY-839

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None
    • Environment:
      Windows XP
    • Estimated Complexity:
      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

      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

        Hide
        Paulex Yang added a comment -

        Verified by Anton and Spark.

        Show
        Paulex Yang added a comment - Verified by Anton and Spark.
        Hide
        spark shen added a comment -

        Verified at r447694

        Show
        spark shen added a comment - Verified at r447694
        Hide
        Paulex Yang added a comment -

        Anton and Spark, updated patch applied at revision r447357, thanks a lot for this enhancement, please verify the problem is fixed as you expected.

        Show
        Paulex Yang added a comment - Anton and Spark, updated patch applied at revision r447357, thanks a lot for this enhancement, please verify the problem is fixed as you expected.
        Hide
        Anton Luht added a comment -

        the patch applied correctly to svn = r447316 and solved problem with WeakHashMap and IdentityHashMap

        Show
        Anton Luht added a comment - the patch applied correctly to svn = r447316 and solved problem with WeakHashMap and IdentityHashMap
        Hide
        spark shen added a comment -

        Would any one try this patch?
        BTW, would any commiter change the component to classlib.

        Show
        spark shen added a comment - Would any one try this patch? BTW, would any commiter change the component to classlib.
        Hide
        spark shen added a comment -

        The old patch of JIRA 866 is outdated. I update the patch
        for this JIRA. In this patch, similar problem of HashMap is also dealt with.

        Show
        spark shen added a comment - The old patch of JIRA 866 is outdated. I update the patch for this JIRA. In this patch, similar problem of HashMap is also dealt with.
        Hide
        Anton Luht added a comment -

        same problem with IdentityHashMap - attaching patch with JUnit test and fix for classlib code

        Show
        Anton Luht added a comment - same problem with IdentityHashMap - attaching patch with JUnit test and fix for classlib code
        Hide
        Anton Luht added a comment -

        patch

        Show
        Anton Luht added a comment - patch

          People

          • Assignee:
            Paulex Yang
            Reporter:
            Anton Luht
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development