Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1073096] - When debugging the rhqctl code I came across to Concur…
Browse files Browse the repository at this point in the history
…rentModificationException. Altought it is unlikely to happen in the production code without debuging, it is still posible -> making the copy of undoTasks, because other thread can modify it simultaneously.
  • Loading branch information
jkremser committed Mar 18, 2014
1 parent 491fb04 commit 5367acf
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ public abstract class ControlCommand {
private ArrayList<Runnable> undoTasks = new ArrayList<Runnable>();

protected void undo() {
Collections.reverse(undoTasks); // do the undo tasks in the reverse order in which they were added to the list
for (Runnable undoTask : undoTasks) {
// perform the undo on the snapshot of undoTasks, because of possible ConcurrentModificationException
List<Runnable> undoTasksCopy = new ArrayList<Runnable>(undoTasks);
Collections.reverse(undoTasksCopy); // do the undo tasks in the reverse order in which they were added to the list
for (Runnable undoTask : undoTasksCopy) {
try {
undoTask.run();
} catch (Throwable t) {
Expand Down

0 comments on commit 5367acf

Please sign in to comment.