Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing through iterator not supported by CopyOnWriteArrayList #209

Closed
krosenvold opened this issue Mar 29, 2011 · 2 comments
Closed

Removing through iterator not supported by CopyOnWriteArrayList #209

krosenvold opened this issue Mar 29, 2011 · 2 comments

Comments

@krosenvold
Copy link
Contributor

Run-listener throwing exception causes this, and it can be seen that removing an element by its iterator is not suppored on copyonwritearraylist.

Caused by: java.lang.IllegalStateException
at java.util.AbstractList$Itr.remove(AbstractList.java:356)
at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:43)
at org.junit.runner.notification.RunNotifier.fireTestRunFinished(RunNotifier.java:68)
at org.junit.runner.JUnitCore.run(JUnitCore.java:158)
at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:51)
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:110)

Fix with the following change or similar:
for (Iterator all = fListeners.iterator(); all.hasNext();){
RunListener next = all.next();
try {
notifyListener(next);
} catch (Exception e) {
fListeners.remove( next); // Remove the offending listener first to avoid an infinite loop
fireTestFailure(new Failure(Description.TEST_MECHANISM, e));
}
}

@dsaff
Copy link
Member

dsaff commented Mar 29, 2011

Nice bug catch. Thanks!

@Stephan202
Copy link
Contributor

For reference: there are other issues with this code, please see #395.

stefanbirkner added a commit to stefanbirkner/junit that referenced this issue Mar 10, 2012
@dsaff dsaff closed this as completed in 3639784 Apr 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants