RFR [8014066] Mistake in documentation of ArrayList#removeRange

Ivan Gerasimov ivan.gerasimov at oracle.com
Thu Mar 13 17:00:02 UTC 2014


Thank you Martin for your feedback!

I'll add the test with the next webrev.
Here's the test I used to check that the exception isn't thrown:

class Test extends java.util.ArrayList<Integer> {
     public static void main(String[] args) throws Throwable {
         Test list = new Test();
         list.add(1);
         list.removeRange(list.size(), list.size());
     }
}

Sincerely yours,
Ivan


On 13.03.2014 20:34, 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?
>
> 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.gerasimov at oracle.com <mailto: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/
>     <http://cr.openjdk.java.net/%7Eigerasim/8014066/0/webrev/>
>
>     Sincerely yours,
>     Ivan
>
>




More information about the core-libs-dev mailing list