Fix gh-11618: Make DefaultModelValidator thread-safe#11739
Open
abhu85 wants to merge 1 commit intoapache:masterfrom
Open
Fix gh-11618: Make DefaultModelValidator thread-safe#11739abhu85 wants to merge 1 commit intoapache:masterfrom
abhu85 wants to merge 1 commit intoapache:masterfrom
Conversation
The validIds field was a non-thread-safe HashSet that could cause ClassCastException when accessed concurrently from multiple threads. This happens when using the BF dependency collector strategy (aether.dependencyCollector.impl=bf) which uses multiple threads. Fixed by: - Using ConcurrentHashMap.newKeySet() instead of HashSet (consistent with the fix already applied in Maven 4 impl module) - Adding null check before contains() since ConcurrentHashMap doesn't allow null keys Fixes apache#11618 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49971d2 to
016c565
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
validIdsfield inDefaultModelValidatorthread-safe usingConcurrentHashMap.newKeySet()contains()sinceConcurrentHashMapdoesn't allow null keysProblem
DefaultModelValidator.validIdsis a non-thread-safeHashSetthat can causeClassCastExceptionwhen accessed concurrently from multiple threads:This issue manifests when using the BF dependency collector strategy (
aether.dependencyCollector.impl=bf) which uses multiple threads for dependency resolution.Solution
Replace
HashSetwithConcurrentHashMap.newKeySet(), which is the same approach already used in the Maven 4 impl module (impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java).Test Plan
mvn spotless:apply- formatting verifiedmvn test -pl compat/maven-model-builder- all 161 tests passgit diff --check- no whitespace issuesCompatibility
This is a backward-compatible fix. The behavior remains the same, but now thread-safe.
Fixes #11618
🤖 Generated with Claude Code