harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r555541 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/AbstractList.java test/api/common/tests/api/java/util/AbstractListTest.java
Date Thu, 12 Jul 2007 08:58:32 GMT
Author: leoli
Date: Thu Jul 12 01:58:31 2007
New Revision: 555541

URL: http://svn.apache.org/viewvc?view=rev&rev=555541
Log:
Apply patch for HARMONY-4398([classlib][luni]AbstractList does not handle expectedModCount
correctly
).

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/AbstractListTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java?view=diff&rev=555541&r1=555540&r2=555541
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/AbstractList.java
Thu Jul 12 01:58:31 2007
@@ -62,13 +62,14 @@
         public void remove() {
             if (expectedModCount == modCount) {
                 try {
-                    AbstractList.this.remove(lastPosition);
-                } catch (IndexOutOfBoundsException e) {
-                    throw new IllegalStateException();
-                }
-                if (modCount != expectedModCount) {
-                    expectedModCount++;
-                }
+					AbstractList.this.remove(lastPosition);
+				} catch (IndexOutOfBoundsException e) {
+					throw new IllegalStateException();
+				} finally {
+					if (modCount != expectedModCount) {
+						expectedModCount++;
+					}
+				}
                 if (pos == lastPosition) {
                     pos--;
                 }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/AbstractListTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/AbstractListTest.java?view=diff&rev=555541&r1=555540&r2=555541
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/AbstractListTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/tests/api/java/util/AbstractListTest.java
Thu Jul 12 01:58:31 2007
@@ -20,10 +20,12 @@
 import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.ConcurrentModificationException;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.NoSuchElementException;
 import java.util.RandomAccess;
 
 public class AbstractListTest extends junit.framework.TestCase {
@@ -195,6 +197,75 @@
             // expected
         }
     }
+
+    class MockArrayList<E> extends AbstractList<E> {
+    	/**
+    	 * 
+    	 */
+    	private static final long serialVersionUID = 1L;
+    	
+    	ArrayList<E> list = new ArrayList<E>();
+    	
+    	public E remove(int idx) {
+    		modCount++;
+    		return list.remove(idx);
+    	}
+
+    	@Override
+    	public E get(int index) {
+    		return list.get(index);
+    	}
+
+    	@Override
+    	public int size() {
+    		return list.size();
+    	}
+    	
+    	public void add(int idx, E o) {
+    		modCount++;
+    		list.add(idx, o);
+    	}
+    }
+    
+    /*
+     * Regression test for HY-4398
+     */
+    public void test_iterator_next() {
+		MockArrayList<String> t = new MockArrayList<String>();
+		t.list.add("a");
+		t.list.add("b");
+		
+		Iterator it = t.iterator();
+		
+		while (it.hasNext()) {
+			it.next();
+		}
+		try {
+            it.next();
+            fail("Should throw NoSuchElementException");
+        } catch (NoSuchElementException cme) {
+            // expected
+        }
+
+        t.add("c");
+        try {
+            it.remove();
+            fail("Should throw NoSuchElementException");
+        } catch (ConcurrentModificationException cme) {
+            // expected
+		}
+		
+		it = t.iterator();
+		try {
+			it.remove();
+			fail("Should throw IllegalStateException");
+		} catch (IllegalStateException ise) {
+			// expected
+		}
+
+		Object value = it.next();
+		assertEquals("a", value);
+	}
 
     /**
      * @tests java.util.AbstractList#subList(int, int)



Mime
View raw message