I assigned this to Paul (hope that's OK) JDK-8168745 Iterator.forEachRemaining vs. Iterator.remove
On Tue, Oct 25, 2016 at 4:13 PM, Paul Sandoz <paul.san...@oracle.com> wrote: > > > On 25 Oct 2016, at 15:16, Martin Buchholz <marti...@google.com> wrote: > > > > Actually, the ArrayList implementation updates fields only at the end of > the iteration, so if an action throws in the middle, the iterator is > semi-corrupted (in the sense that remove() will remove the "wrong" element > and next will return previously visited elements). > > Good point. > > > > I think it's best to say in the spec that after calling > forEachRemaining, subsequent operations on the Iterator are undefined > (whether or not the action throws). > > > Yes (and for an action calling remove). > > > > For consistency, we should probably keep the historic behavior that > remove() after forEachRemaining() removes the last element, even though > that is not to be encouraged. > > > > Agreed. > > Paul. >