RFR [8014066] Mistake in documentation of ArrayList#removeRange

Martin Buchholz martinrb at google.com
Thu Mar 13 16:34:40 UTC 2014

I notice there are zero jtreg tests for removeRange.  That should be fixed.

I notice there is a removeRange in CopyOnWriteArrayList, but it is
package-private instead of "protected", which seems like an oversight.  Can
Doug remember any history on that?

I notice that AbstractList.removeRange contains no @throws.  That should be

The existing @throws javadoc from CopyOnWriteArrayList seems better:

     * @throws IndexOutOfBoundsException if fromIndex or toIndex out of
     *         ({@code fromIndex < 0 || toIndex > size() || toIndex <

This paragraph in AbstractList

     * <p>This method is called by the {@code clear} operation on this list
     * and its subLists.  Overriding this method to take advantage of
     * the internals of the list implementation can <i>substantially</i>
     * improve the performance of the {@code clear} operation on this list
     * and its subLists.

looks like it belongs inside the @implSpec (it's not a requirement on

ObTesting (a start)

import java.util.*;

public class RemoveRange {
    static class PublicArrayList<E> extends ArrayList<E> {
        PublicArrayList(int cap) { super(cap); }
        public void removeRange(int fromIndex, int toIndex) {
            super.removeRange(fromIndex, toIndex);
    public static void main(String[] args) throws Throwable {
        PublicArrayList<String> x = new PublicArrayList<String>(11);
        for (int i = 0; i < 11; i++) x.add(null);
        x.removeRange(x.size(), x.size());

On Thu, Mar 13, 2014 at 8:29 AM, Ivan Gerasimov
<ivan.gerasimov at oracle.com>wrote:

> Hello!
> Would you please review a simple fix of the javadoc for
> ArrayList#removeRange() method?
> The doc says that IndexOutOfBoundsException is thrown if fromIndex or
> toIndex is out of range (fromIndex < 0 || fromIndex >= size() || toIndex >
> size() || toIndex < fromIndex).
> The condition 'fromIndex >= size()' isn't true and should be removed from
> the doc.
> For example, the code list.removeRange(size(), size()) does not throw any
> exception.
> BUGURL: https://bugs.openjdk.java.net/browse/JDK-8014066
> WEBREV: http://cr.openjdk.java.net/~igerasim/8014066/0/webrev/
> Sincerely yours,
> Ivan

More information about the core-libs-dev mailing list