commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r567739 - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/CollectionUtils.java test/org/apache/commons/collections/TestCollectionUtils.java
Date Mon, 20 Aug 2007 16:11:47 GMT
Author: bayard
Date: Mon Aug 20 09:11:47 2007
New Revision: 567739

URL: http://svn.apache.org/viewvc?rev=567739&view=rev
Log:
Making it so CollectionUtils.size(null) returns 0 and not an IllegalArgumentException as per
COLLECTIONS-230

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java?rev=567739&r1=567738&r2=567739&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/CollectionUtils.java
Mon Aug 20 09:11:47 2007
@@ -892,6 +892,9 @@
      * @since Commons Collections 3.1
      */
     public static int size(Object object) {
+        if (object == null) {
+            return 0;
+        }
         int total = 0;
         if (object instanceof Map) {
             total = ((Map) object).size();

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java?rev=567739&r1=567738&r2=567739&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/TestCollectionUtils.java
Mon Aug 20 09:11:47 2007
@@ -739,7 +739,9 @@
 
     //-----------------------------------------------------------------------
     public void testSize_List() {
-        List list = new ArrayList();
+        List list = null;
+        assertEquals(0, CollectionUtils.size(list));
+        list = new ArrayList();
         assertEquals(0, CollectionUtils.size(list));
         list.add("a");
         assertEquals(1, CollectionUtils.size(list));
@@ -793,10 +795,6 @@
         assertEquals(2, CollectionUtils.size(list.iterator()));
     }
     public void testSize_Other() {
-        try {
-            CollectionUtils.size(null);
-            fail("Expecting IllegalArgumentException");
-        } catch (IllegalArgumentException e) {}
         try {
             CollectionUtils.size("not a list");
             fail("Expecting IllegalArgumentException");



Mime
View raw message