Skip to content

Commit

Permalink
bz-63921 Using a "live" keySet() can result in ConcurrentModification…
Browse files Browse the repository at this point in the history
…Exception
  • Loading branch information
jaikiran committed Jan 10, 2020
1 parent dfeee59 commit c4aeb9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions WHATSNEW
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Fixed bugs:
optional dependencies were missing. This has now been fixed.
Bugzilla Report 63438

* Fixes a potential ConcurrentModificationException in XMLLogger.
Bugzilla Report 63921

Other changes:
--------------
Expand Down
12 changes: 9 additions & 3 deletions src/main/org/apache/tools/ant/XmlLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
import java.util.Stack;

import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -346,9 +348,13 @@ private TimedElement getTaskElement(Task task) {
if (element != null) {
return element;
}
return tasks.keySet().stream().filter(UnknownElement.class::isInstance)
.filter(key -> ((UnknownElement) key).getTask() == task).findFirst()
.map(key -> tasks.get(key)).orElse(null);
final Set<Task> knownTasks = new HashSet<>(tasks.keySet());
for (final Task t : knownTasks) {
if (t instanceof UnknownElement && ((UnknownElement) t).getTask() == task) {
return tasks.get(t);
}
}
return null;
}

/**
Expand Down

0 comments on commit c4aeb9c

Please sign in to comment.