Sweet this was an issue for me and I never thought to remove from the
iterator too!
Joshua T. Pyle
On 9/13/05, Bryan Lewis <brya..aine.rr.com> wrote:
> Here's another way that worked for me.
>
> // Use a ListIterator to allow concurrent modification.
> for (ListIterator it = getRoles().listIterator(); it.hasNext();
> ) {
> Role role = (Role) it.next();
> // Remove it from the iterator too, to avoid a
> // ConcurrentModificationException.
> it.remove();
> removeFromRoles(role);
> }
>
> ----- Original Message -----
> From: Jeff de Vries
> To: cayenne-use..bjectstyle.org
> Sent: Monday, September 12, 2005 11:33 PM
> Subject: Filtering to-many relationship and ConcurrentModificationException
>
> I'm trying to iterate over a to-many relationship filtering out unwanted
> objects, something like this:
> Iterator it = getFooArray().iterator();
> while (it.hasNext()) {
> Foo f = (Foo) it.next();
> if some condition on f is true {
> removeFromFooArray(f);
> }
> }
> At runtime, I'm getting a ConcurrentModificationException,
> which can be raised either in a multithreading situation (which I don't
> think I'm in), or by "invalidating" the contract of the container (i.e.
> while in a loop deleting items all of sudden adding an item).
>
> Does removeFromXXXArray() invalidate any iterators iterating over the list?
> Is there a better way to do what I'm trying to do? Apologies in advance if
> this is just a dumb Java question.
>
> Thanks,
> Jeff de Vries
>
>
-- Joshua T. Pyle Go has always existed.
This archive was generated by hypermail 2.0.0 : Tue Sep 13 2005 - 15:18:14 EDT