Skip to content

[Backport 4.0.x] Avoid IllegalStateException on duplicate profile ids in DefaultModelBuilder#12506

Merged
ascheman merged 1 commit into
apache:maven-4.0.xfrom
aschemaven:backport-40x-12419-duplicate-profile-ids
Jul 19, 2026
Merged

[Backport 4.0.x] Avoid IllegalStateException on duplicate profile ids in DefaultModelBuilder#12506
ascheman merged 1 commit into
apache:maven-4.0.xfrom
aschemaven:backport-40x-12419-duplicate-profile-ids

Conversation

@ascheman

Copy link
Copy Markdown
Contributor

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 key from Collectors.toMap in DefaultModelBuilder.getProfileActivations. Maven 3 accepts these POMs; duplicate-id diagnostics remain with the validator.

This was also the root cause of the massembly-969 IT 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: DefaultModelBuilderTest 13/13 green (includes the new duplicate-profile-ids regression test).

🤖 Generated with Claude Code

…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 gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 throws IllegalStateException on duplicate keys) with a position-indexed List<Activation>. The injectProfileActivations method is updated to iterate by index, preserving the 1:1 correspondence between profiles and their activations regardless of duplicate IDs.
  • Proper null handlinggetProfileActivations() now maps all profiles (including those without activations), but the if (activation != null) guard in injectProfileActivations correctly skips profiles without activations.
  • Good testtestDuplicateProfileIdsRetainActivations() verifies two profiles with the same "default" ID coexist and each retains its distinct activation (one activeByDefault, 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.

@ascheman ascheman added the bug Something isn't working label Jul 19, 2026
@ascheman
ascheman merged commit 6b87d5f into apache:maven-4.0.x Jul 19, 2026
22 checks passed
@github-actions github-actions Bot added this to the 4.0.0-rc-6 milestone Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-4.0.x bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants