On 03/13/2014 12:34 PM, Martin Buchholz wrote:
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?

CopyOnWriteArrayList does not extend AbstractList, but its
sublist does. The sublist relies on COWAL.removeRange only for clear.
So COWAL sublist clearing uses the same idea as
AbstractList, and gives it the same name, but it is not the
same AbstractList method, so need not be protected.

-Doug



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

The existing @throws javadoc from CopyOnWriteArrayList seems better:

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

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 
subclasses)

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.gerasi...@oracle.com
<mailto:ivan.gerasi...@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
    <https://bugs.openjdk.java.net/browse/JDK-8014066>
    WEBREV: http://cr.openjdk.java.net/~__igerasim/8014066/0/webrev/
    <http://cr.openjdk.java.net/~igerasim/8014066/0/webrev/>

    Sincerely yours,
    Ivan



Reply via email to