Skip to content

Bugfix: use GAV and not GAPV in source labels for profiles - #12406

Merged
cstamas merged 2 commits into
apache:masterfrom
cstamas:issue-12405
Jul 5, 2026
Merged

cstamas merged 2 commits into
apache:masterfrom
cstamas:issue-12405

Conversation

@cstamas

@cstamas cstamas commented Jun 30, 2026

Copy link
Copy Markdown
Member

This introduces no behaviour change between Maven 3 and 4, merely the labels for "source" of profiles got different.

Fixes #12405

This introduces no behaviour change between Maven 3 and 4, merely
the labels for "source" of profiles got different.

Fixes apache#12405
@cstamas
cstamas requested review from gnodet and hboutemy June 30, 2026 16:55
@cstamas cstamas self-assigned this Jun 30, 2026
@cstamas cstamas added the bug Something isn't working label Jun 30, 2026
@cstamas cstamas added this to the 4.1.0 milestone Jun 30, 2026

@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: Bugfix — use GAV and not GAPV in source labels for profiles

Scope: 1 file changed (DefaultProjectBuilder.java), +11 / −1

Note: This review covers project conventions and code correctness. It does not replace specialized tools such as CodeRabbit, Sourcery, or SonarCloud.

Summary

The PR fixes a Maven 3 → 4 behavioral discrepancy in how profile source labels are identified in MavenProject.setInjectedProfileIds(). Maven 3's ModelData#getId() returned GAV (groupId:artifactId:version), but Maven 4's Model#getId() returns GAPV (groupId:artifactId:packaging:version). This subtle difference causes issues identifying reactor projects, as the packaging component is irrelevant for that purpose.

The fix replaces result.getEffectiveModel().getId() in the fallback path with a new getModelDataId() helper that emulates Maven 3's GAV format.

✅ No blocking issues found

The change is correct, well-scoped, and well-documented:

  • Correctness: The new getModelDataId() correctly emulates Maven 3's ModelData#getId() — producing groupId:artifactId:version with [inherited] placeholders for null values
  • Scope: Minimal and focused — single logical change in the fallback path
  • Issue linkage: Properly linked to #12405
  • Tests: Existing test testActivatedProfileBySource in DefaultMavenProjectBuilderTest already asserts GAV format for profile source keys
  • Documentation: Clear Javadoc on the new method explaining what it emulates

Observations (non-blocking)

  1. Potential reuse of ModelProblemUtils.toId(model) — The DefaultModelBuilder already has ModelProblemUtils.toId(model) which produces the same GAV format and is used for setting the profilesByModel map keys (lines 1490, 1961). The new getModelDataId() does similar work but with different null-handling ([inherited] vs resolving from parent → [unknown-*]). Since ModelProblemUtils is package-private in org.apache.maven.impl.model and the consumer is in org.apache.maven.project, direct reuse isn't possible — so the separate method is justified. For the effective model (fully resolved), both methods produce identical output.

  2. Potentially related pre-existing inconsistency (out of scope) — In DefaultModelBuilder.java at line 1944, there is addActivePomProfiles(cached.model().getId(), cached.activatedProfiles()) which uses Model#getId() (GAPV), while lines 1490 and 1961 correctly use ModelProblemUtils.toId() (GAV) for the same map. This could cause cache-hit entries to be stored under GAPV keys while everything else uses GAV keys. This might be worth investigating as a follow-up.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

@gnodet

gnodet commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This should be backported to 4.0.x.

@gnodet

gnodet commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Follow-up: same GAPV vs GAV inconsistency in DefaultModelBuilder.java (line 1944)

The readAsParentModel() method has two paths that both call addActivePomProfiles(), but they use different key formats for the same parent model:

Path Line Key format Code
Cache miss 1961 GAV ✅ ModelProblemUtils.toId(model) → g:a:v
Cache hit 1944 GAPV ❌ cached.model().getId() → g:a:p:v

The cache-miss path was already fixed (the comment on line 1960 even says "Use ModelProblemUtils.toId() to get groupId:artifactId:version format (without packaging)"), but the cache-hit path on line 1944 was missed — it still calls Model.getId() which includes packaging.

Practical impact

When multiple child projects share the same parent:

  1. Child A resolves parent P first → cache miss → P's profiles stored under GAV key (org.example:parent:1.0)
  2. Child B resolves parent P second → cache hit → P's profiles stored under GAPV key (org.example:parent:pom:1.0)

So in DefaultProjectBuilder at line 807, when it iterates profilesByModel and calls setInjectedProfileIds(entry.getKey(), ...), the source label for the same parent's profiles would be different depending on whether the child happened to be first or second to resolve it. Non-deterministic — same bug class as this PR.

Suggested fix

One-liner on line 1944 of DefaultModelBuilder.java:

// Before (GAPV):
addActivePomProfiles(cached.model().getId(), cached.activatedProfiles());

// After (GAV):
addActivePomProfiles(ModelProblemUtils.toId(cached.model()), cached.activatedProfiles());

ModelProblemUtils is already imported and used in the same file.

…urce keys

The cache-hit path in readAsParentModel() used Model.getId() which
returns groupId:artifactId:packaging:version (GAPV), while the
cache-miss path correctly used ModelProblemUtils.toId() which returns
groupId:artifactId:version (GAV). This inconsistency could cause
the same parent's profiles to be stored under different keys depending
on whether the parent model was resolved from cache or freshly built.

Follow-up to apache#12406.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@cstamas
cstamas marked this pull request as ready for review July 5, 2026 12:54
@cstamas
cstamas merged commit 923106a into apache:master Jul 5, 2026
22 checks passed
@cstamas
cstamas deleted the issue-12405 branch July 5, 2026 12:56
cstamas added a commit that referenced this pull request Jul 5, 2026
…12424)

This introduces no behaviour change between Maven 3 and 4, merely the labels for "source" of profiles got different.

Fixes #12405

Backport of 923106a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maven 4 vs 3

2 participants