--- old/src/share/classes/java/util/ArrayList.java 2014-03-17 02:08:34.186906634 +0400 +++ new/src/share/classes/java/util/ArrayList.java 2014-03-17 02:08:33.626913673 +0400 @@ -609,11 +609,13 @@ * @throws IndexOutOfBoundsException if {@code fromIndex} or * {@code toIndex} is out of range * ({@code fromIndex < 0 || - * fromIndex >= size() || * toIndex > size() || * toIndex < fromIndex}) */ protected void removeRange(int fromIndex, int toIndex) { + if (fromIndex > toIndex) + throw new IndexOutOfBoundsException( + "From Index: " + fromIndex + " > To Index: " + toIndex); modCount++; int numMoved = size - toIndex; System.arraycopy(elementData, toIndex, elementData, fromIndex, --- old/test/java/util/Collection/MOAT.java 2014-03-17 02:08:35.634888430 +0400 +++ new/test/java/util/Collection/MOAT.java 2014-03-17 02:08:35.166894314 +0400 @@ -173,6 +173,9 @@ equal(singletonMap.size(), 1); testMap(singletonMap); testImmutableMap(singletonMap); + + // Protected ArrayList#removeRange + NewArrayList.testRemoveRange(); } private static void checkContainsSelf(Collection c) { @@ -1393,5 +1396,44 @@ return set.size(); } } + private static class NewArrayList extends ArrayList { + // ArrayList#removeRange is protected, so is tested + // from within a derived class + public static void testRemoveRange() { + final int MAX_ITEM = 8; + final int START_INDEX = -2; + final int END_INDEX = MAX_ITEM + 2; + final NewArrayList list = new NewArrayList(); + try { list.removeRange(list.size(), list.size()); } + catch (Throwable t) { unexpected(t); } + for (int i = 0; i <= MAX_ITEM; ++i) { + list.add(i); + } + + for (int fromIndex = START_INDEX; fromIndex <= END_INDEX; ++fromIndex) { + for (int toIndex = START_INDEX; toIndex <= END_INDEX; ++toIndex) { + if (fromIndex < 0 + || toIndex > list.size() + || toIndex < fromIndex) { + final int FROM_INDEX = fromIndex; + final int TO_INDEX = toIndex; + THROWS(IndexOutOfBoundsException.class, + new Fun() { void f() { list.removeRange(FROM_INDEX, TO_INDEX); }}); + } else { + try { + NewArrayList list1 = (NewArrayList)list.clone(); + list1.removeRange(fromIndex, toIndex); + for (int i = 0, j = 0; i < list1.size(); ++i, ++j) { + if (j == fromIndex) + j = toIndex; + check(list1.get(i) == j); + } + } catch (Throwable t) { unexpected(t); } + } + } + } + + } + } }