RFR  Mistake in documentation of ArrayList#removeRange
david.holmes at oracle.com
Tue Mar 18 06:22:31 UTC 2014
On 17/03/2014 8:37 AM, Ivan Gerasimov wrote:
> Here is yet another iteration of the fix:
> 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().
> 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
> 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? ;-)
> Moved the test to MOAT.java
> The test looks a bit foreign over there, but reuses some of the
I'll leave the testing comments to others more qualified.
> Sincerely yours,
More information about the core-libs-dev