harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r764215 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Collections.java test/api/common/org/apache/harmony/luni/tests/java/util/Collections2Test.java
Date Sat, 11 Apr 2009 16:22:53 GMT
Author: ndbeyer
Date: Sat Apr 11 16:22:52 2009
New Revision: 764215

URL: http://svn.apache.org/viewvc?rev=764215&view=rev
Log:
Apply modified patch for HARMONY-6122 - [classlib][luni] java.util.Collections.swap(List<?>
list, int i, int j) should throw IndexOutOfBoundsException when i equals to j and is also
out of boundary

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/Collections2Test.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java?rev=764215&r1=764214&r2=764215&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
Sat Apr 11 16:22:52 2009
@@ -1982,12 +1982,17 @@
      * 
      * @throws IndexOutOfBoundsException
      *             if index1 or index2 is out of range of this list
+     * @since 1.4
      */
     @SuppressWarnings("unchecked")
     public static void swap(List<?> list, int index1, int index2) {
         if (list == null) {
             throw new NullPointerException();
         }
+        final int size = list.size();
+        if (index1 < 0 || index1 >= size || index2 < 0 || index2 >= size) {
+            throw new IndexOutOfBoundsException();
+        }
         if (index1 == index2) {
             return;
         }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/Collections2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/Collections2Test.java?rev=764215&r1=764214&r2=764215&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/Collections2Test.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/Collections2Test.java
Sat Apr 11 16:22:52 2009
@@ -464,4 +464,33 @@
         assertTrue(emptyList instanceof RandomAccess);
     }
 
+    // Regression test for http://issues.apache.org/jira/browse/HARMONY-6122
+    public void test_Collections_swap_IndexOutOfBoundsException() {
+        try {
+            Collections.swap(new ArrayList<Object>(), -1, 3);
+            fail("IOOBE expected");
+        } catch (IndexOutOfBoundsException e) {
+        }
+        
+        List<Object> list = new ArrayList<Object>();
+        list.add("0");
+        try {
+            Collections.swap(list, 0, -1);
+            fail("IOOBE expected");
+        } catch (IndexOutOfBoundsException e) {
+        }
+        
+        try {
+            Collections.swap(list, 0, 3);
+            fail("IOOBE expected");
+        } catch (IndexOutOfBoundsException e) {
+        }
+        
+        try {
+            Collections.swap(new ArrayList<Object>(), 3, 3);
+            fail("IOOBE expected");
+        } catch (IndexOutOfBoundsException e) {
+        }
+    }
+
 }



Mime
View raw message