harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r652391 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/TreeMap.java test/api/common/org/apache/harmony/luni/tests/java/util/TreeMapTest.java
Date Wed, 30 Apr 2008 14:46:55 GMT
Author: hindessm
Date: Wed Apr 30 07:46:51 2008
New Revision: 652391

URL: http://svn.apache.org/viewvc?rev=652391&view=rev
Log:
Fix for "[#HARMONY-5788] [classlib][util] TreeMap.entrySet().contains()
returns true for entries with null value".  Thanks to Jimmy for
helping make the solution more efficient.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TreeMapTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java?rev=652391&r1=652390&r2=652391&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java Wed
Apr 30 07:46:51 2008
@@ -1202,8 +1202,9 @@
                 public boolean contains(Object object) {
                     if (object instanceof Map.Entry) {
                         Map.Entry<K, V> entry = (Map.Entry<K, V>) object;
-                        Object v1 = TreeMap.this.get(entry.getKey()), v2 = entry.getValue();
-                        return v1 == null ? v2 == null : v1.equals(v2);
+                        K key = entry.getKey();
+                        Object v1 = TreeMap.this.get(key), v2 = entry.getValue();
+                        return v1 == null ? ( v2 == null && TreeMap.this.containsKey(key)
) : v1.equals(v2);
                     }
                     return false;
                 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TreeMapTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TreeMapTest.java?rev=652391&r1=652390&r2=652391&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TreeMapTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/TreeMapTest.java
Wed Apr 30 07:46:51 2008
@@ -643,6 +643,31 @@
     }
 
     /**
+     * Tests entrySet().contains() method behaviour with respect to entries
+     * with null values.
+     * Regression test for HARMONY-5788.
+     */
+    public void test_entrySet_contains() throws Exception {
+        TreeMap master = new TreeMap<String, String>();
+        TreeMap test_map = new TreeMap<String, String>();
+
+        master.put("null", null);
+        Object[] entry = master.entrySet().toArray();
+        assertFalse("Empty map should not contain the null-valued entry",
+                    test_map.entrySet().contains(entry[0]));
+
+        test_map.put("null", null);
+        assertTrue("entrySet().containsAll(...) should work with null values",
+                   test_map.entrySet().containsAll(master.entrySet()));
+
+        master.clear();
+        master.put("null", '0');
+        entry = master.entrySet().toArray();
+        assertFalse("Null-valued entry should not equal non-null-valued entry",
+                    test_map.entrySet().contains(entry[0]));
+    }
+
+    /**
      * Sets up the fixture, for example, open a network connection. This method
      * is called before a test is executed.
      */



Mime
View raw message