Avoid ConcurrentModificationExceptions

AggregateMojo.getDescendants() can end up adding descendants while
it's iterating over them. This separates the addition from the
iteration to avoid this.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
Stephen Kitt
2015-10-09 17:07:27 +02:00
parent e7f518264a
commit 1852b9dbb2

View File

@@ -173,15 +173,14 @@ public class AggregateMojo extends BaseDependencyCheckMojo {
}
}
}
Set<MavenProject> addedDescendants = new HashSet<MavenProject>();
for (MavenProject dec : descendants) {
for (String mod : dec.getModules()) {
try {
File mpp = new File(dec.getBasedir(), mod);
mpp = mpp.getCanonicalFile();
if (mpp.compareTo(p.getBasedir()) == 0 && descendants.add(p)) {
if (getLog().isDebugEnabled()) {
getLog().debug(String.format("Decendent module %s added", p.getName()));
}
if (mpp.compareTo(p.getBasedir()) == 0) {
addedDescendants.add(p);
}
} catch (IOException ex) {
if (getLog().isDebugEnabled()) {
@@ -190,6 +189,11 @@ public class AggregateMojo extends BaseDependencyCheckMojo {
}
}
}
for (MavenProject addedDescendant : addedDescendants) {
if (descendants.add(addedDescendant) && getLog().isDebugEnabled()) {
getLog().debug(String.format("Decendent module %s added", addedDescendant.getName()));
}
}
}
} while (size != 0 && size != descendants.size());
if (getLog().isDebugEnabled()) {