RFR [8014066] Mistake in documentation of ArrayList#removeRange

Ivan Gerasimov ivan.gerasimov at oracle.com
Wed Mar 19 08:19:43 UTC 2014


Thank you Ulf!

On 19.03.2014 2:12, Ulf Zibis wrote:
> Am 18.03.2014 19:28, schrieb Ivan Gerasimov:
>>
>> Assuming this last iteration is OK, should the next step be a CCC 
>> request?
>
> Do you mean? :
>      /*
>       * ...
> +     * It is assumed that fromIndex <= toIndex, otherwise the 
> behaviour of this method is undefined.
>       * ...
>  -     *          toIndex < fromIndex})
>       * ...
>      */
>      protected void removeRange(int fromIndex, int toIndex) {
>          ...
>

The (fromIndex > toIndex) condition is checked now, so the behavior of 
the method is defined - it throws an exception.

> Please remove and replace inline by size - toIndex:
>  621         int numMoved = size - toIndex;
>

It is done this way throughout the class.
I don't think it has to be changed in this particular place.

Improving modCound handling can be done with a different RFE I guess, as 
it doesn't connected to the rest of the fix.

Sincerely yours,
Ivan

>
> About modCount:
>
> Wouldn't it be more correct to code? :
>
>  616         if (fromIndex > toIndex) {
>  617             throw new IndexOutOfBoundsException(
>  618                     outOfBoundsMsg(fromIndex, toIndex));
>  619         }
>  620         try {
>  621             modCount++;
>  622             System.arraycopy(elementData, toIndex, elementData, 
> fromIndex,
>  623                     size - toIndex);
>  624         } catch (IndexOutOfBoundsException ioobe) {
>  625             modCount--;
>  626             throw ioobe;
>  627         }
>
> Of even better :
>
>  000     private int[] modCount = { 0 };
>  ...
>  616         if (fromIndex > toIndex) {
>  617             throw new IndexOutOfBoundsException(
>  618                     outOfBoundsMsg(fromIndex, toIndex));
>  619         }
>  620         System.arraycopy(elementData, toIndex, elementData, 
> fromIndex,
>  621                 size - toIndex, modCount);
>
> Or :
>
>  000 public class ArrayList ... implements ModCounter {
>  001     private int modCount = 0;
>  001     void incModCount() {
>  001         modCount++;
>  004    }
>  ...
>  616         if (fromIndex > toIndex) {
>  617             throw new IndexOutOfBoundsException(
>  618                     outOfBoundsMsg(fromIndex, toIndex));
>  619         }
>  620         System.arraycopy(elementData, toIndex, elementData, 
> fromIndex,
>  621                 size - toIndex, this);
>
> -Ulf
>
>
>
>




More information about the core-libs-dev mailing list