DefaultModelBuilder: Thread-unsafe HashSet inside ConcurrentHashMap
Found in: maven-4.0.x branch
File: impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java (lines 454-457)
Severity: High
Description
mappedSources is a ConcurrentHashMap<GAKey, Set<ModelSource>>. While computeIfAbsent is atomic for the map, the returned HashSet values are shared across threads and are NOT thread-safe:
public void putSource(String groupId, String artifactId, ModelSource source) {
mappedSources
.computeIfAbsent(new GAKey(groupId, artifactId), k -> new HashSet<>())
.add(source);
}
If multiple threads concurrently add sources for the same GAKey, the internal structure of the HashSet can become corrupted (lost updates, infinite loops during iteration, etc.). This is exercisable during parallel reactor builds where loadFilePom calls putSource from within executor tasks running concurrently.
DefaultModelBuilder: Thread-unsafe HashSet inside ConcurrentHashMap
Found in: maven-4.0.x branch
File:
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java(lines 454-457)Severity: High
Description
mappedSourcesis aConcurrentHashMap<GAKey, Set<ModelSource>>. WhilecomputeIfAbsentis atomic for the map, the returnedHashSetvalues are shared across threads and are NOT thread-safe:If multiple threads concurrently add sources for the same
GAKey, the internal structure of theHashSetcan become corrupted (lost updates, infinite loops during iteration, etc.). This is exercisable during parallel reactor builds whereloadFilePomcallsputSourcefrom within executor tasks running concurrently.