commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r348273 - in /jakarta/commons/proper/collections/trunk: ./ src/java/org/apache/commons/collections/ src/java/org/apache/commons/collections/map/ src/test/org/apache/commons/collections/ src/test/org/apache/commons/collections/map/
Date Tue, 22 Nov 2005 22:24:35 GMT
Author: scolebourne
Date: Tue Nov 22 14:24:25 2005
New Revision: 348273

URL: http://svn.apache.org/viewcvs?rev=348273&view=rev
Log:
StaticBucketMap containsKey doesn't check nulls correctly
bug 37567, from Kazuya Ujihara

Modified:
    jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
    jakarta/commons/proper/collections/trunk/project.xml
    jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/StaticBucketMap.java
    jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/StaticBucketMap.java
    jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestStaticBucketMap.java
    jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java

Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html?rev=348273&r1=348272&r2=348273&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html (original)
+++ jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html Tue Nov 22 14:24:25 2005
@@ -93,6 +93,7 @@
 <li>MultiHashMap.putAll(multimap) - Was adding the collection as a single item rather
than individually [35631]</li>
 <li>Flat3Map.equals() - Fix to make flat mode comparison actually work [34917]</li>
 <li>TransformedMap.putAll - Now allows putAll of an empty map [34686]</li>
+<li>StaticBucketMap - containsKey - Fix incorrect null checking [37567]</li>
 <li>AbstractMapBag.BagIterator.remove - Removing the last entry used to break the class
invariants [35747]</li>
 <li>BoundedFifoBuffer/CircularFifoBuffer - Fix serialization to work in case where
buffer serialized when full [31433]</li>
 <li>BoundedFifoBuffer - Fix iterator remove bug causing ArrayIndexOutOfBounds error
[33071]</li>

Modified: jakarta/commons/proper/collections/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/project.xml?rev=348273&r1=348272&r2=348273&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/project.xml (original)
+++ jakarta/commons/proper/collections/trunk/project.xml Tue Nov 22 14:24:25 2005
@@ -347,6 +347,9 @@
       <name>Jeff Turner</name>
     </contributor>
     <contributor>
+      <name>Kazuya Ujihara</name>
+    </contributor>
+    <contributor>
       <name>Jeff Varszegi</name>
     </contributor>
     <contributor>

Modified: jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/StaticBucketMap.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/StaticBucketMap.java?rev=348273&r1=348272&r2=348273&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/StaticBucketMap.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/StaticBucketMap.java
Tue Nov 22 14:24:25 2005
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2002-2004 The Apache Software Foundation
+ *  Copyright 2002-2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -97,6 +97,7 @@
  * @author Paul Jack
  * @author Leo Sutic
  * @author Janek Bogucki
+ * @author Kazuya Ujihara
  */
 public final class StaticBucketMap implements Map {
 
@@ -277,7 +278,7 @@
 
             while( n != null )
             {
-                if( n.key == null || ( n.key != null && n.key.equals( key ) ) )
+                if( n.key == key || ( n.key != null && n.key.equals( key ) ) )
                 {
                     return true;
                 }

Modified: jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/StaticBucketMap.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/StaticBucketMap.java?rev=348273&r1=348272&r2=348273&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/StaticBucketMap.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/map/StaticBucketMap.java
Tue Nov 22 14:24:25 2005
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2002-2004 The Apache Software Foundation
+ *  Copyright 2002-2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -98,6 +98,7 @@
  * @author Paul Jack
  * @author Leo Sutic
  * @author Janek Bogucki
+ * @author Kazuya Ujihara
  */
 public final class StaticBucketMap implements Map {
 
@@ -230,7 +231,7 @@
             Node n = buckets[hash];
 
             while (n != null) {
-                if (n.key == null || (n.key != null && n.key.equals(key))) {
+                if (n.key == key || (n.key != null && n.key.equals(key))) {
                     return true;
                 }
 

Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestStaticBucketMap.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestStaticBucketMap.java?rev=348273&r1=348272&r2=348273&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestStaticBucketMap.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestStaticBucketMap.java
Tue Nov 22 14:24:25 2005
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2004 The Apache Software Foundation
+ *  Copyright 2001-2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
 import org.apache.commons.collections.map.AbstractTestMap;
 
 /**
- * Unit tests 
+ * Unit tests.
  * {@link org.apache.commons.collections.StaticBucketMap}.
  * 
  * @version $Revision$ $Date$
@@ -57,4 +57,39 @@
             pre + "Values" + post
         };
     }   
+
+    // Bugzilla 37567
+    public void test_get_nullMatchesIncorrectly() {
+        StaticBucketMap map = new StaticBucketMap(17);
+        map.put(null, "A");
+        assertEquals("A", map.get(null));
+        // loop so we find a string that is in the same bucket as the null
+        for (int i = 'A'; i <= 'Z'; i++) {
+            String str = String.valueOf((char) i);
+            assertEquals("String: " + str, null, map.get(str));
+        }
+    }
+
+    public void test_containsKey_nullMatchesIncorrectly() {
+        StaticBucketMap map = new StaticBucketMap(17);
+        map.put(null, "A");
+        assertEquals(true, map.containsKey(null));
+        // loop so we find a string that is in the same bucket as the null
+        for (int i = 'A'; i <= 'Z'; i++) {
+            String str = String.valueOf((char) i);
+            assertEquals("String: " + str, false, map.containsKey(str));
+        }
+    }
+
+    public void test_containsValue_nullMatchesIncorrectly() {
+        StaticBucketMap map = new StaticBucketMap(17);
+        map.put("A", null);
+        assertEquals(true, map.containsValue(null));
+        // loop so we find a string that is in the same bucket as the null
+        for (int i = 'A'; i <= 'Z'; i++) {
+            String str = String.valueOf((char) i);
+            assertEquals("String: " + str, false, map.containsValue(str));
+        }
+    }
+
 }

Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java?rev=348273&r1=348272&r2=348273&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/map/TestStaticBucketMap.java
Tue Nov 22 14:24:25 2005
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2004 The Apache Software Foundation
+ *  Copyright 2001-2005 The Apache Software Foundation
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -22,8 +22,8 @@
 import org.apache.commons.collections.BulkTest;
 
 /**
- * Unit tests 
- * {@link org.apache.commons.collections.StaticBucketMap}.
+ * Unit tests.
+ * {@link StaticBucketMap}.
  * 
  * @version $Revision$ $Date$
  * 
@@ -39,7 +39,7 @@
         return BulkTest.makeSuite(TestStaticBucketMap.class);
     }
 
-    public static void main(String[] args[]) {
+    public static void main(String[] args) {
         String[] testCaseName = { TestStaticBucketMap.class.getName() };
         junit.textui.TestRunner.main(testCaseName);
     }
@@ -56,5 +56,40 @@
             pre + "KeySet" + post,
             pre + "Values" + post
         };
-    }   
+    }
+
+    // Bugzilla 37567
+    public void test_get_nullMatchesIncorrectly() {
+        StaticBucketMap map = new StaticBucketMap(17);
+        map.put(null, "A");
+        assertEquals("A", map.get(null));
+        // loop so we find a string that is in the same bucket as the null
+        for (int i = 'A'; i <= 'Z'; i++) {
+            String str = String.valueOf((char) i);
+            assertEquals("String: " + str, null, map.get(str));
+        }
+    }
+
+    public void test_containsKey_nullMatchesIncorrectly() {
+        StaticBucketMap map = new StaticBucketMap(17);
+        map.put(null, "A");
+        assertEquals(true, map.containsKey(null));
+        // loop so we find a string that is in the same bucket as the null
+        for (int i = 'A'; i <= 'Z'; i++) {
+            String str = String.valueOf((char) i);
+            assertEquals("String: " + str, false, map.containsKey(str));
+        }
+    }
+
+    public void test_containsValue_nullMatchesIncorrectly() {
+        StaticBucketMap map = new StaticBucketMap(17);
+        map.put("A", null);
+        assertEquals(true, map.containsValue(null));
+        // loop so we find a string that is in the same bucket as the null
+        for (int i = 'A'; i <= 'Z'; i++) {
+            String str = String.valueOf((char) i);
+            assertEquals("String: " + str, false, map.containsValue(str));
+        }
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message