Repository navigation
[Backport maven-4.0.x] Fix #13469: prefer default bindings for unqualified lookups in standalone injector - #13545
Conversation
…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-bot
left a comment
There was a problem hiding this comment.
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.
…tCacheDoesNotShareActivationWithProjectParent
gnodet-bot
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
… match actual DIException thrown
gnodet-bot
left a comment
There was a problem hiding this comment.
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.
…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).
…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)
…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
[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.