Bug in ArrayList iterator
Daniel Fuchs
daniel.fuchs at oracle.com
Wed Jan 7 10:16:15 UTC 2015
Interesting... I would have expected it to throw
java.util.ConcurrentModificationException right
away, but it only does so if the list contains
exactly 1 or more than 2 elements...
best regards,
-- daniel
On 07/01/15 10:45, Remi Forax wrote:
> A simple Java question, what this code does ?
>
> ArrayList<String> list = new ArrayList<>();
> list.add("foo");
> list.add("bar");
> for(String s: list) {
> list.remove(s);
> }
>
> :(
>
> Rémi
> tip: the bug lies in ArrayList.Itr.hasNext() (and
> AbstractList.Itr.hasNext()).
>
More information about the core-libs-dev
mailing list