[Backport 4.0.x] Avoid IllegalStateException on duplicate profile ids in DefaultModelBuilder#12506
Merged
ascheman merged 1 commit intoJul 19, 2026
Conversation
…uilder (apache#12419) Save/restore profile activations positionally instead of keyed by profile id, so POMs with duplicate profile ids (e.g. javafx <=20) no longer crash dependency collection. Duplicate-id diagnostics remain with the validator. Fixes apache#10209 (cherry picked from commit 67a94a1)
gnodet
approved these changes
Jul 19, 2026
gnodet
left a comment
Contributor
There was a problem hiding this comment.
Review: [Backport 4.0.x] Avoid IllegalStateException on duplicate profile ids
Clean backport of #12419 to maven-4.0.x. The fix is the same logic, correctly adapted for Maven 4's immutable model API.
What this PR does well
- Correct fix — replaces
Collectors.toMap(Profile::getId, ...)(which throwsIllegalStateExceptionon duplicate keys) with a position-indexedList<Activation>. TheinjectProfileActivationsmethod is updated to iterate by index, preserving the 1:1 correspondence between profiles and their activations regardless of duplicate IDs. - Proper null handling —
getProfileActivations()now maps all profiles (including those without activations), but theif (activation != null)guard ininjectProfileActivationscorrectly skips profiles without activations. - Good test —
testDuplicateProfileIdsRetainActivations()verifies two profiles with the same "default" ID coexist and each retains its distinct activation (oneactiveByDefault, one property-based). - Excellent PR description — documents the real-world impact (javafx ≤ 20 POMs, massembly-969 IT failure) and links to the upstream fix.
Checklist
| Check | Status |
|---|---|
| Tests | ✓ New regression test with test fixture POM |
| Docs | ✓ PR body documents context and verification |
| Commit convention | ✓ |
| Public API / backward compat | ✓ Private methods only; restores Maven 3 behavior |
| Security | N/A |
| CI | ⏳ In progress (initial-build pending) |
Note: CI is still running but the code is identical in logic to #12419 (which passed all CI and was approved). Approving based on code correctness.
LGTM.
Reviewed with Claude Code on behalf of Guillaume Nodet. This review was generated by an AI agent and may contain inaccuracies; please verify all suggestions before applying.
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.
Backport of #12419 to
maven-4.0.x— clean cherry-pick of 67a94a1, no conflicts.This fixes the MNG-8418 (#10209) regression on the rc-6 line: POMs with duplicate profile ids (e.g. javafx ≤ 20 with its OS-named profiles) crash dependency collection with
IllegalStateException: Duplicate keyfromCollectors.toMapinDefaultModelBuilder.getProfileActivations. Maven 3 accepts these POMs; duplicate-id diagnostics remain with the validator.This was also the root cause of the
massembly-969IT failure in maven-assembly-plugin's Maven 4 lane (apache/maven-assembly-plugin#1311) before the plugin worked around it by bumping to javafx 26 (apache/maven-assembly-plugin#1325) — real projects depending on older javafx POMs still hit it on rc-5.Verified on this branch:
DefaultModelBuilderTest13/13 green (includes the new duplicate-profile-ids regression test).🤖 Generated with Claude Code