harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r474918 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/TreeMap.java test/java/tests/api/java/util/TreeMapTest.java
Date Tue, 14 Nov 2006 18:41:48 GMT
Author: tellison
Date: Tue Nov 14 10:41:47 2006
New Revision: 474918

URL: http://svn.apache.org/viewvc?view=rev&rev=474918
Log:
Fix for ill behaved collator used in TreeMap.

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java?view=diff&rev=474918&r1=474917&r2=474918
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
Tue Nov 14 10:41:47 2006
@@ -186,7 +186,7 @@
 
         @Override
         public boolean hasNext() {
-            return (node != null) && (cmp.compare(node.key, endKey) < 0);
+            return (node != null && endKey != null) && (cmp.compare(node.key,
endKey) < 0);
         }
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java?view=diff&rev=474918&r1=474917&r2=474918
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/util/TreeMapTest.java
Tue Nov 14 10:41:47 2006
@@ -18,6 +18,8 @@
 package tests.api.java.util;
 
 import java.io.Serializable;
+import java.text.CollationKey;
+import java.text.Collator;
 import java.util.AbstractMap;
 import java.util.Collection;
 import java.util.Comparator;
@@ -293,11 +295,33 @@
         
         // Regression for Harmony-1066
         assertTrue(head instanceof Serializable);
+        
+        // Regression for ill-behaved collator
+        Collator c = new Collator() {
+            public int compare(String o1, String o2) {
+                if (o1 == null) {
+                    return 0;
+                }
+                return o1.compareTo(o2);
+            }
+
+            public CollationKey getCollationKey(String string) {
+                return null;
+            }
+
+            public int hashCode() {
+                return 0;
+            }
+        };
+
+        TreeMap<String, String> treemap = new TreeMap<String, String>(c);
+        treemap.put("key", "value"); //$NON-NLS-1$ //$NON-NLS-2$
+        assertEquals(0, treemap.headMap(null).size());
 	}
 
 	/**
-	 * @tests java.util.TreeMap#keySet()
-	 */
+     * @tests java.util.TreeMap#keySet()
+     */
 	public void test_keySet() {
 		// Test for method java.util.Set java.util.TreeMap.keySet()
 		Set ks = tm.keySet();



Mime
View raw message