Re: Filtering to-many relationship and ConcurrentModificationException

From: Gili (cowwo..bs.darktech.org)
Date: Mon Sep 12 2005 - 23:35:11 EDT

  • Next message: Bryan Lewis: "Re: Filtering to-many relationship and ConcurrentModificationException"

            Yeah, I ran into the same thing. You're supposed to get back a list
    from the relationship, wrap it in your own ArrayList, and then proceed
    to removeFromList(). When you remove from the underlying list while
    iterating over it it will obviously through a
    ConcurrentModificationException.

            So try:

    List fooArray = new ArrayList(getFooArray());

            and iterate over that...

    Gili

    Jeff de Vries wrote:
    > 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
    >

    -- 
    http://www.desktopbeautifier.com/
    



    This archive was generated by hypermail 2.0.0 : Mon Sep 12 2005 - 23:35:10 EDT