]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ArrayList.jva (removeRange): If toIndex == fromIndex do nothing...
authorMark Wielaard <mark@klomp.org>
Sat, 6 Apr 2002 08:26:08 +0000 (08:26 +0000)
committerMark Wielaard <mark@gcc.gnu.org>
Sat, 6 Apr 2002 08:26:08 +0000 (08:26 +0000)
        * java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do
        nothing, if toIndex < fromIndex throw IndexOutIfBoundsException.

From-SVN: r51947

libjava/ChangeLog
libjava/java/util/ArrayList.java

index 3c356d44800c967f0833316427768361ebf99e5a..a48ba5157501ea941b212c5c11a7bf26cae5cf59 100644 (file)
@@ -1,3 +1,8 @@
+2002-04-05  Mark Wielaard <mark@klomp.org>
+
+       * java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do
+       nothing, if toIndex < fromIndex throw IndexOutIfBoundsException.
+
 2002-04-05  Adam Megacz <adam@xwt.org>
 
         * exception.cc (abort): added static modifier
index 34dc48ac17907273d3e846cc57a27a52331f7514..59ce974b18f507d26cc2990f17aef548b7e436b6 100644 (file)
@@ -437,19 +437,23 @@ public class ArrayList extends AbstractList
 
   /**
    * Removes all elements in the half-open interval [fromIndex, toIndex).
-   * You asked for it if you call this with invalid arguments.
+   * Does nothing when toIndex is equal to fromIndex.
    *
    * @param fromIndex the first index which will be removed
    * @param toIndex one greater than the last index which will be removed
+   * @throws IndexOutOfBoundsException if fromIndex &gt; toIndex
    */
   protected void removeRange(int fromIndex, int toIndex)
   {
-    if (fromIndex != toIndex)
+    int change = toIndex - fromIndex;
+    if (change > 0)
       {
         modCount++;
         System.arraycopy(data, toIndex, data, fromIndex, size - toIndex);
-        size -= toIndex - fromIndex;
+        size -= change;
       }
+    else if (change < 0)
+      throw new IndexOutOfBoundsException();
   }
 
   /**