harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r561214 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/AbstractList.java test/api/common/tests/api/java/util/AbstractListTest.java
Date Tue, 31 Jul 2007 02:30:13 GMT
Author: leoli
Date: Mon Jul 30 19:30:12 2007
New Revision: 561214

URL: http://svn.apache.org/viewvc?view=rev&rev=561214
Log:
Apply patch for HARMONY-4576([classlib][luni] AbstractList's remove method will throw unexpected
ConcurrentModificationException).

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=561214&r1=561213&r2=561214
==============================================================================
--- 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
Mon Jul 30 19:30:12 2007
@@ -60,23 +60,25 @@
         }
 
         public void remove() {
-            if (expectedModCount == modCount) {
-                try {
-					AbstractList.this.remove(lastPosition);
-				} catch (IndexOutOfBoundsException e) {
-					throw new IllegalStateException();
-				} finally {
-					if (modCount != expectedModCount) {
-						expectedModCount++;
-					}
-				}
-                if (pos == lastPosition) {
-                    pos--;
-                }
-                lastPosition = -1;
-            } else {
+            if (this.lastPosition == -1) {
+                throw new IllegalStateException();
+            }
+
+            if (expectedModCount != modCount) {
+                throw new ConcurrentModificationException();
+            }
+
+            try {
+                AbstractList.this.remove(lastPosition);
+            } catch (IndexOutOfBoundsException e) {
                 throw new ConcurrentModificationException();
             }
+            
+            expectedModCount = modCount;
+            if (pos == lastPosition) {
+                pos--;
+            }
+            lastPosition = -1;
         }
     }
 

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=561214&r1=561213&r2=561214
==============================================================================
--- 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
Mon Jul 30 19:30:12 2007
@@ -297,4 +297,45 @@
     }
 
     protected void doneSuite() {}
+    
+    class MockRemoveFailureArrayList<E> extends AbstractList<E> {
+
+		@Override
+		public E get(int location) {
+			// TODO Auto-generated method stub
+			return null;
+		}
+
+		@Override
+		public int size() {
+			// TODO Auto-generated method stub
+			return 0;
+		}
+		
+		public E remove(int idx) {
+    		modCount+=2;
+    		return null;
+    	}
+		
+		public int getModCount(){
+			return modCount;
+		}
+    }
+    
+    //test remove for failure by inconsistency of modCount and expectedModCount 
+    public void test_remove(){
+    	MockRemoveFailureArrayList<String> mrfal = new MockRemoveFailureArrayList<String>();
+    	Iterator<String> imrfal= mrfal.iterator();
+    	imrfal.next();
+    	imrfal.remove();
+    	try{
+    		imrfal.remove();
+    	}
+    	catch(ConcurrentModificationException e){
+    		fail("Excepted to catch IllegalStateException not ConcurrentModificationException");
+    	}
+    	catch(IllegalStateException e){
+    		//Excepted to catch IllegalStateException here
+    	}
+    }
 }



Mime
View raw message