You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2002/06/24 10:12:42 UTC

DO NOT REPLY [Bug 10168] New: - Bug in CollectionUtils

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10168>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=10168

Bug in CollectionUtils

           Summary: Bug in CollectionUtils
           Product: Commons
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Collections
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: MacBelgium@Toughguy.net


Hi,

there is a bug in CollectionUtils. If you pass in a Collection object which is 
not an instance of List to the CollectionUtils.index() methods, the method 
doesn't work: it just returns the given Collection instead of the i-th value in 
the Collection.

I've already reported this (including a patch) to the commons-dev mailinglist, 
but there was no reaction, that's why I'm trying it this way.

Here is the patch (if possible, I will also add an attachment including this 
patch)

regards,
Maarten

cvs diff -u CollectionUtils.java 
Index: CollectionUtils.java
===================================================================
RCS file: /home/cvspublic/jakarta-
commons/collections/src/java/org/apache/commons/collections/CollectionUtils.java
,v
retrieving revision 1.8
diff -u -r1.8 CollectionUtils.java
--- CollectionUtils.java	12 Jun 2002 03:59:15 -0000	1.8
+++ CollectionUtils.java	18 Jun 2002 12:23:34 -0000
@@ -500,6 +500,17 @@
                 }
             }
         }
+        else if(obj instanceof Collection) {
+            Iterator iterator = ((Collection)obj).iterator();
+            while(iterator.hasNext()) {
+                idx--;
+                if(idx == -1) {
+                    return iterator.next();
+                } else {
+                    iterator.next();
+                }
+            }
+        }
         return obj;
     }

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>