RFR [8014066] Mistake in documentation of ArrayList#removeRange

David Holmes david.holmes at oracle.com
Tue Mar 18 06:22:31 UTC 2014

Hi Ivan,

On 17/03/2014 8:37 AM, Ivan Gerasimov wrote:
> Here is yet another iteration of the fix:
> http://cr.openjdk.java.net/~igerasim/8014066/3/webrev/
> 1)
> The condition 'fromIndex >= size()' is removed from the spec.
> I prefer removing it rather than replacing it with 'fromIndex > size()'
> for two reasons:
> - 'fromIndex > size()' already follows on from two other conditions
> (toIndex > size() || toIndex < fromIndex);
> - it is consistent with the spec for CopyOnWriteArrayList#removeRange().


> 2)
> Kept the check for 'fromIndex > toIndex' in removeRange().
> While I understand that this should not add anything significant to the
> current code, as currently removeRange() is always called with valid
> arguments.
> However, if it is stated in the spec that in case of 'fromIndex >
> toIndex' an exception is thrown, I believe it should be thrown,
> otherwise why it's stated?

I postulate that there may have been some confusion here regarding the 
logical size of the ArrayList and the actual size of the elementData 
array. If size were actually elementData.length, then System.arraycopy 
would throw IOOBE if fromIndex > toIndex.

So this extra check is fine, and fixes a bug, though to nitpick as it is 
spec'd as toIndex<fromIndex is there any reason to implement it the 
other way around? ;-)

> 3)
> Moved the test to MOAT.java
> The test looks a bit foreign over there, but reuses some of the
> infrastructure.

I'll leave the testing comments to others more qualified.


> Sincerely yours,
> Ivan

More information about the core-libs-dev mailing list