From 8e9603b0c204c9ea0099bc379be3de18da9f9488 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 6 Apr 2002 08:26:08 +0000 Subject: ArrayList.jva (removeRange): If toIndex == fromIndex do nothing... * java/util/ArrayList.jva (removeRange): If toIndex == fromIndex do nothing, if toIndex < fromIndex throw IndexOutIfBoundsException. From-SVN: r51947 --- libjava/java/util/ArrayList.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libjava/java') diff --git a/libjava/java/util/ArrayList.java b/libjava/java/util/ArrayList.java index 34dc48a..59ce974 100644 --- a/libjava/java/util/ArrayList.java +++ b/libjava/java/util/ArrayList.java @@ -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 > 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(); } /** -- cgit v1.1