Bug in ArrayList iterator

Paul Sandoz paul.sandoz at oracle.com
Thu Jan 8 08:36:19 UTC 2015

> On 01/08/2015 03:24 AM, David Holmes wrote:
>> So don't do that.

Yes, don't. However, it can happen unintentionally and such an exception helps catch bugs. This can more easily occur when there is some "distance" between iterating and operating on the list. So it's about strengthening the best-effort basis of the implementation (ideally without unduly perturbing existing time and space characteristics).

On Jan 8, 2015, at 9:11 AM, Remi Forax <forax at univ-mlv.fr> wrote:
> Hi David,
> while I agree that fail-fast behavior should be done on the best effort basis,
> i think like Paul said that the size should be stored in a field of the iterator because
> i don't see the point to try to support the fact that the size of the collection
> can change during the iteration.
> so in my opinion, it's not a bug but the current implementation of ArrayList.Itr should be changed
> or maybe there is a case where supporting a size changed is valid ?

Any size change (via addition or removal, bulk or otherwise) is a structural modification in some form or another to the underlying data structure. The only allowed modification i am aware of when iterating is that performed by the iterator itself via Iterator.remove.


More information about the core-libs-dev mailing list