RFR [8014066] Mistake in documentation of ArrayList#removeRange

Ivan Gerasimov ivan.gerasimov at oracle.com
Fri Mar 14 11:19:50 UTC 2014


Thanks Peter for the comments.

On 14.03.2014 14:53, Peter Levart wrote:
> On 03/14/2014 08:05 AM, Ivan Gerasimov wrote:
>> One thing I noticed is that some methods I mentioned above 
>> (List.subList(), Arrays.sort(), etc) throw IllegalArgumentException 
>> when fromIndex > toIndex, not IndexOutOfBoundException.
>> Wouldn't it be more correct to adopt this into removeRange() too?
>
> The question is, what exception should be thrown for removeRange(0, 
> -1) then... The order of checks matters and should be specified if two 
> kinds of exceptions are thrown...
>

In my opinion, the order of the checks should match the order of the 
listed exceptions in the spec.

If the order is:
@throws IndexOutOfBoundException if either index is negative or either 
index is greater than size()
@throws IllegalArgumentException if (fromIndex > toIndex)

then removeRange(0, -1) should throw IndexOutOfBoundException.

Sincerely yours,
Ivan




More information about the core-libs-dev mailing list