commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joc...@apache.org
Subject svn commit: r1076034 - in /commons/proper/collections: branches/COLLECTIONS_3_2_BRANCH/ branches/COLLECTIONS_3_2_BRANCH/src/java/org/apache/commons/collections/iterators/ branches/COLLECTIONS_3_2_BRANCH/src/test/org/apache/commons/collections/iterators...
Date Tue, 01 Mar 2011 22:10:11 GMT
Author: jochen
Date: Tue Mar  1 22:10:10 2011
New Revision: 1076034

URL: http://svn.apache.org/viewvc?rev=1076034&view=rev
Log:
PR: COLLECTIONS-360
Prevent an NPE in FilterListIterator.next() and FilterListIterator.previous()

Modified:
    commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/pom.xml
    commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
    commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java
    commons/proper/collections/trunk/pom.xml
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java

Modified: commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/pom.xml?rev=1076034&r1=1076033&r2=1076034&view=diff
==============================================================================
--- commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/pom.xml (original)
+++ commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/pom.xml Tue Mar  1 22:10:10
2011
@@ -364,6 +364,9 @@
       <name>Serhiy Yevtushenko</name>
     </contributor>
     <contributor>
+      <name>Sai Zhang</name>
+    </contributor>
+    <contributor>
       <name>Jason van Zyl</name>
     </contributor>
   </contributors>

Modified: commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/java/org/apache/commons/collections/iterators/FilterListIterator.java?rev=1076034&r1=1076033&r2=1076034&view=diff
==============================================================================
--- commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
(original)
+++ commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
Tue Mar  1 22:10:10 2011
@@ -236,6 +236,10 @@ public class FilterListIterator implemen
             }
         }
 
+        if (iterator == null) {
+            return false;
+        }
+
         while(iterator.hasNext()) {
             Object object = iterator.next();
             if(predicate.evaluate(object)) {
@@ -266,6 +270,9 @@ public class FilterListIterator implemen
             }
         }
 
+        if (iterator == null) {
+            return false;
+        }
         while(iterator.hasPrevious()) {
             Object object = iterator.previous();
             if(predicate.evaluate(object)) {

Modified: commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java?rev=1076034&r1=1076033&r2=1076034&view=diff
==============================================================================
--- commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java
(original)
+++ commons/proper/collections/branches/COLLECTIONS_3_2_BRANCH/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java
Tue Mar  1 22:10:10 2011
@@ -21,11 +21,14 @@ import java.util.List;
 import java.util.ListIterator;
 import java.util.Random;
 
+import junit.framework.Assert;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.PredicateUtils;
+import org.apache.commons.collections.list.GrowthList;
 
 /**
  * Tests the FilterListIterator class.
@@ -289,6 +292,18 @@ public class TestFilterListIterator exte
         assertEquals(expected.previous(),filtered.previous());
     }
 
+    /**
+     * Test for {@link https://issues.apache.org/jira/browse/COLLECTIONS-360 COLLECTIONS-360}.
+     */
+    public void testCollections360() throws Throwable {
+        GrowthList var7 = new GrowthList();
+        Predicate var9 = PredicateUtils.anyPredicate((java.util.Collection)var7);
+        FilterListIterator var13 = new FilterListIterator(var9);
+        Assert.assertFalse(var13.hasNext());
+        org.apache.commons.collections.iterators.FilterListIterator var14 = new org.apache.commons.collections.iterators.FilterListIterator(var9);
+        Assert.assertFalse(var14.hasPrevious());
+    }
+
     // Utilities
 
     private void walkForward(ListIterator expected, ListIterator testing) {

Modified: commons/proper/collections/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/pom.xml?rev=1076034&r1=1076033&r2=1076034&view=diff
==============================================================================
--- commons/proper/collections/trunk/pom.xml (original)
+++ commons/proper/collections/trunk/pom.xml Tue Mar  1 22:10:10 2011
@@ -351,6 +351,9 @@
       <name>Serhiy Yevtushenko</name>
     </contributor>
     <contributor>
+      <name>Sai Zhang</name>
+    </contributor>
+    <contributor>
       <name>Jason van Zyl</name>
     </contributor>
   </contributors>

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterListIterator.java?rev=1076034&r1=1076033&r2=1076034&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/iterators/FilterListIterator.java
Tue Mar  1 22:10:10 2011
@@ -227,6 +227,9 @@ public class FilterListIterator<E> imple
             clearNextObject();
         }
 
+        if (iterator == null) {
+            return false;
+        }
         while (iterator.hasNext()) {
             E object = iterator.next();
             if (predicate.evaluate(object)) {
@@ -256,6 +259,9 @@ public class FilterListIterator<E> imple
             clearPreviousObject();
         }
 
+        if (iterator == null) {
+            return false;
+        }
         while (iterator.hasPrevious()) {
             E object = iterator.previous();
             if (predicate.evaluate(object)) {

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java?rev=1076034&r1=1076033&r2=1076034&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/iterators/TestFilterListIterator.java
Tue Mar  1 22:10:10 2011
@@ -17,12 +17,16 @@
 package org.apache.commons.collections.iterators;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Random;
 
 import junit.framework.TestCase;
 import org.apache.commons.collections.Predicate;
+import org.apache.commons.collections.PredicateUtils;
+import org.apache.commons.collections.list.GrowthList;
+import org.junit.Assert;
 
 /**
  * Tests the FilterListIterator class.
@@ -279,6 +283,18 @@ public class TestFilterListIterator exte
         assertEquals(expected.previous(), filtered.previous());
     }
 
+    /**
+     * Test for {@link https://issues.apache.org/jira/browse/COLLECTIONS-360 COLLECTIONS-360}.
+     */
+    public void testCollections360() throws Throwable {
+        Collection<Predicate<Object>> var7 = new GrowthList<Predicate<Object>>();
+        Predicate<Object> var9 = PredicateUtils.anyPredicate(var7);
+        FilterListIterator<Object> var13 = new FilterListIterator<Object>(var9);
+        Assert.assertFalse(var13.hasNext());
+        FilterListIterator<Object> var14 = new FilterListIterator<Object>(var9);
+        Assert.assertFalse(var14.hasPrevious());
+    }
+
     // Utilities
 
     private void walkForward(ListIterator<?> expected, ListIterator<?> testing)
{



Mime
View raw message