Bug in ArrayList iterator

Chris Hegarty chris.hegarty at oracle.com
Wed Jan 7 12:18:15 UTC 2015


On 07/01/15 11:25, Doug Lea wrote:
> On 01/07/2015 04:45 AM, 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);
>>    }
>>
>
> I have a vague recollection that this issue has come up before,
> and that nothing was done about it because it broke compatibility
> with some existing code. Maybe someone with records of past CCC
> decisions could check this?

For the record ( thanks Alan! ) 4902078 [1] proposed to fix this 
previously, but that was by changing hasNext() to throw CME ( which I 
don't agree with ).

-Chris.

[1] https://bugs.openjdk.java.net/browse/JDK-4902078

>
> -Doug
>



More information about the core-libs-dev mailing list