Details about the known misuse from the MUBench dataset.
Description:
Modifying a collection after an Iterator has been created and continue to use the Iterator afterwards. Often happens with foreach loops.
Found 2584 threads for 'ConcurrentModificationException' on StackOverflow. Top 1% by relevance: Modifying the collection after creating the iterator:
class CME {
public void misuse(Collection<Object> c) {
Iterator<Object> i = c.iterator();
c.add(new Object());
if (i.hasNext())
i.next();
}
}
Code with Pattern(s):
public class DoNotModify {
public void pattern(Collection<Object> c, Object element) {
Iterator<Object> i = c.iterator();
if (i.hasNext())
i.next();
}
}