elharo opened a new issue, #12597:
URL: https://github.com/apache/maven/issues/12597
# 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:
```java
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]