You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2009/04/11 18:22:53 UTC

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

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) {
+        }
+    }
+
 }