Skip to content

[Backport maven-4.0.x] Fix #13469: prefer default bindings for unqualified lookups in standalone injector - #13545

Merged
gnodet merged 7 commits into
apache:maven-4.0.xfrom
gnodet:backport/13471-to-4.0.x
Oct 16, 2026
Merged

gnodet merged 7 commits into
apache:maven-4.0.xfrom
gnodet:backport/13471-to-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

[Backport #13471] Fix #13469: prefer default bindings for unqualified lookups in standalone injector.

Fixes #13469.

When ApiRunner requests an unqualified Session, the standalone injector could return a named provider (e.g. mvnup's) instead of the default one when both have equal priority, causing ApiRunner to lose the requested local repository.

  • Injector now prefers default binding when priorities tie on an unqualified lookup
  • Equal default bindings produce an ambiguity error (rather than arbitrary selection)
  • Distinct named providers remain available through List and Map<String, T> injection
  • Repeat registrations of the same provider are collapsed
  • Added tests: InjectorImplTest, BindingSelectionTest, ApiRunnerSettingsTest

…jector

Fixes apache#13469.

When ApiRunner requests an unqualified Session, the standalone injector could return a named provider (e.g. mvnup's) instead of the default one when both have equal priority, causing ApiRunner to lose the requested local repository.

- Injector now prefers default binding when priorities tie on an unqualified lookup
- Equal default bindings produce an ambiguity error (rather than arbitrary selection)
- Distinct named providers remain available through List<T> and Map<String, T> injection
- Repeat registrations of the same provider are collapsed
- Added tests: InjectorImplTest, BindingSelectionTest, ApiRunnerSettingsTest

(cherry picked from commit f5778f5)
@gnodet gnodet added this to the 4.0.0 milestone Oct 15, 2026
@gnodet gnodet added bug Something isn't working backport mvn4 labels Oct 15, 2026

@gnodet-bot gnodet-bot 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.

The fix is correct and the test coverage is thorough. Two Javadoc precision issues worth tightening before merge.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet-bot gnodet-bot 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.

The Javadoc update is an improvement over the previous IllegalStateException, but the declared exception type can be made more precise.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

…ation context

When activating parent profiles, start(Map) was overriding the context's
model.withProperties(parentProps) so that getModelProperty() returned the
parent POM's own declared properties. This caused condition-based profiles
that reference POM properties (e.g. ${pom.declared.prop} == 'hello') to
fire during parent model activation, even though the design intent (apache#13390)
is that POM-declared properties must not self-activate profiles.

The fix introduces a separate interpolationProperties field that is used
exclusively by interpolatePath() for resolving path placeholders (e.g.
${message.file} in file-activated profiles, needed for apache#10375). These
properties are intentionally NOT exposed through getModelProperty(), so
they cannot activate property-based or condition-based profiles.

- start(Map) now stores the map as interpolationProperties instead of
  calling model.withProperties() which affected getModelProperty()
- interpolate() checks interpolationProperties before getModelProperty()
  so path interpolation still works with parent properties
- getModelProperty() continues to read from the outer model (which may
  be Model.newInstance() with empty properties in the test scenario),
  so POM-declared property conditions correctly do not fire
…adoc

DIException is in org.apache.maven.di.impl and is not importable in Injector.java
without adding an internal import. Use IllegalStateException instead, which matches
what maven-4.0.x already uses, and avoids the javadoc 'reference not found' error.

@gnodet-bot gnodet-bot 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.

The updated Javadoc better describes the failure scenarios, but the declared exception type still doesn't match the implementation.

@throws IllegalStateException — both getInstance(Class) and getInstance(Key) overloads declare this, but InjectorImpl actually throws DIException (which extends RuntimeException directly, not IllegalStateException). As confirmed by the new tests added in this PR (assertThrows(DIException.class, ...)), callers who catch IllegalStateException will silently miss the exception.

Consider using @throws RuntimeException (or @throws DIException if you want to be precise and expose the concrete type).

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet-bot gnodet-bot 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.

Following up on my earlier reviews — the @throws IllegalStateException issue has been addressed. The final choice of @throws RuntimeException is correct: DIException (the concrete type actually thrown) extends RuntimeException directly, and using the common base type avoids exposing the impl-package class in the public interface Javadoc. The O(n) complexity note from the previous review was informational only. All prior findings are resolved.

LGTM.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet gnodet added mvn40 and removed mvn4 labels Oct 16, 2026
@gnodet
gnodet merged commit 3e1cb91 into apache:maven-4.0.x Oct 16, 2026
23 checks passed
@gnodet
gnodet deleted the backport/13471-to-4.0.x branch October 16, 2026 09:03
gnodet added a commit that referenced this pull request Oct 19, 2026
…th interpolation (#13555)

The start(Map<String,String>) method previously passed the parent's
properties via model.withProperties(), which made them accessible through
getModelProperty() and thus able to self-activate property-based and
condition-based profiles — exactly the regression that #13390 aimed to fix.

Introduce a dedicated interpolationProperties field that is checked only
inside interpolate(), before the model's own properties. This lets parent
file profiles resolve path placeholders (e.g. ${message.file}) correctly
(#10375) without exposing those properties to ProfileActivationContext
callers that drive profile activation (#13390).

Backported from PR #13545 (maven-4.0.x).
gnodet added a commit to gnodet/maven that referenced this pull request Oct 19, 2026
…d parent contexts activate POM-property conditions

Commit 267e65f (backport of PR apache#13545) introduced a dedicated
interpolationProperties field to prevent POM-declared properties from
self-activating profiles via start(Map). However, it incorrectly dropped
the model.withProperties(interpolationProperties) call that makes those
properties accessible via getModelProperty() in non-sandboxed (project
parent) contexts.

The 4.0.x implementation keeps both:
- model.withProperties(map) so getModelProperty() works for project parents
- interpolationProperties stored separately for path interpolation

The sandbox (withoutUserPropertiesAndFilesystem()) overrides getModelProperty()
to return null, which is the guard against POM property self-activation in
dependency/external builds (apache#13390). Non-sandboxed project parent builds
should still be able to activate condition-based profiles that reference
POM-declared properties.

Fixes testResolvedDependencyParentCacheDoesNotShareActivationWithProjectParent
at line 380: assertEquals("activated", profile.pom.condition)
gnodet added a commit that referenced this pull request Oct 19, 2026
…ation context (#13556)

Fix a logical gap between two independent fixes that both landed on master today:

- #10375 (`ce26838575`) — activate parent file profiles with the parent's properties,
  using `start(Map)` → `model.withProperties(parentProps)`
- #13390 (`d3cc17bc22`) — stop POM properties from self-activating profiles in external builds

The problem: `start(Map)` still calls `model.withProperties(modelProperties)`, which means
`getModelProperty()` returns the parent POM's own declared properties. This directly
contradicts the design intent of #13390: POM-declared properties must not drive profile
activation in external builds.

This commit (backported from #13545) reconciles both fixes:

- Introduces a separate `interpolationProperties` field used **only** inside `interpolate()`
  for path placeholder resolution (e.g. `${message.file}` in file-condition profiles)
- `start(Map)` no longer calls `model.withProperties(...)` — the model's own properties
  remain unchanged, so `getModelProperty()` stays clean
- A parent POM's declared properties can now be used to resolve path placeholders in its
  file-based profiles without being able to self-activate its property-based or
  condition-based profiles

The Javadoc on both the field and `start(Map)` explains the #10375/#13390 relationship.

Backport: #13545
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bug Something isn't working mvn40

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants