Bug 130525 - removeAll problem in DelegatingEList
Summary: removeAll problem in DelegatingEList
Status: VERIFIED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: Core (show other bugs)
Version: 2.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Marcelo Paternostro CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2006-03-06 05:56 EST by Ronald Steinhau CLA
Modified: 2008-07-03 22:31 EDT (History)
2 users (show)

See Also:
nboldt: iplog+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ronald Steinhau CLA 2006-03-06 05:56:29 EST
The following code shows a fix to a potential problem of the removeAll implementation in DelegatingEList:

	 public boolean removeAll(Collection collection) 
	  {
	    boolean modified = false;
	    for (ListIterator i = delegateListIterator(); i.hasNext(); )
	    {
	      if (collection.contains(i.next()))
	      {
	        //remove(i.previousIndex()); -- this caused the exception!!!
	      	i.remove(); // this fixed the exception in our case
	        modified = true;
	      }
	    }

	    return modified;
	  }

The current code (the documented out line of this code snippet) does call a remove on the list which leads to a concurrent modificatioon exception. I think the iterator remove should be called and in our scenario the exception disappeared.
Comment 1 Ed Merks CLA 2006-03-06 08:15:32 EST
Ronald,

Thanks for reporting this.  I've command the fix to change the code to this:

  public boolean removeAll(Collection collection) 
  {
    boolean modified = false;
    for (ListIterator i = listIterator(); i.hasNext(); )
    {
      if (collection.contains(i.next()))
      {
        i.remove();
        modified = true;
      }
    }

    return modified;
  }

I.e., what you suggested, but I've also changed the iterator being used to ensure that the overriden remove(int) method is called when remove() is called on the iterator.

The retainAll methods has the same problem and is similarly fixed.
Comment 2 Ed Merks CLA 2006-03-06 12:52:14 EST
[contrib email="mail@ronald-steinhau.de"/]
Comment 3 Nick Boldt CLA 2006-03-09 11:35:31 EST
Fixed in 2.2.0 I200603090000
Comment 4 Nick Boldt CLA 2008-01-28 16:46:27 EST
Move to verified as per bug 206558.
Comment 5 Nick Boldt CLA 2008-07-03 22:31:47 EDT
Add iplog flag to whole bug as there's no attachment here.