Skip to content

Fix #13469: prefer default bindings for unqualified lookups - #13471

Merged
gnodet merged 10 commits into
apache:masterfrom
ikxeno:fix/13469-default-binding-selection
Oct 15, 2026
Merged

gnodet merged 10 commits into
apache:masterfrom
ikxeno:fix/13469-default-binding-selection

Conversation

@ikxeno

@ikxeno ikxeno commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #13469.

I ran into this while working on mvnval. When ApiRunner requests an unqualified Session, the standalone injector can return mvnup's named provider instead of the default one. Both have the same priority, so the result depends on iteration order. If mvnup's provider wins, ApiRunner loses the requested local repository.

The injector now prefers the default binding when priorities tie on an unqualified lookup. Equal default bindings produce an ambiguity error. That includes bindImplicit(OuterClass.class) when the outer class contains two @Named("") implementations of the same interface; previously, an unqualified lookup picked one arbitrarily. Repeat registrations of a provider are collapsed, while distinct providers remain available through List<T> and Map<String, T> injection.

I added tests for these cases, including an ApiRunner test with the named Session registered first. The mvnval tests also pass.

Validation: mvn -B -q -o -pl impl/maven-cli -am test '-Dtest=InjectorImplTest,BindingSelectionTest,ApiRunnerSettingsTest,ValidateInvokerTest*' -Dsurefire.failIfNoSpecifiedTests=false -Drat.skip=true (88 tests).


With Maven CLI on the classpath, an unqualified Session lookup can
select the named mvnup provider at the same priority. ApiRunner then
loses the requested local repository.

Prefer the default binding at equal priority and fail on remaining
ties. Collapse repeat registrations while preserving distinct
bindings for collection injection.

Cover both the injector and ApiRunner with regression tests.
@github-actions

This comment has been minimized.

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

Fix looks correct and the test suite is thorough (26 scenarios covering default preference, dedup, programmatic bindings, initializer identity, ambiguity detection, and diagnostic messages). Two documentation gaps to address before merging.

✅ Pre-fix validation: 21/26 new tests fail when the source fix is reverted (tests kept in place), all 26 pass with the fix. The failures match exactly the bugs described in the PR.

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 review — 1 of the 4 issues has been addressed; 3 remain open.

  • PRRT_kwDOAAMmk86r1vV6 (InjectorImplTest behavioral change) — ⚠️ partially addressed: the new bindingOuterClassRegistersBothInnerImplementations() test validates the ambiguity detection, which is good. The PR description still does not call out this as a breaking change for callers of bindImplicit(OuterClass.class) when the outer class has multiple same-interface @Named("") implementations. A one-line addition to the PR description would close this.
  • PRRT_kwDOAAMmk86r1vWG (@throws in Injector) — ⚠️ evolved: the @throws IllegalStateException was removed, but no replacement @throws was added — see inline comment below.
  • PRRT_kwDOAAMmk86r1vWM (LinkedHashSet comment) — ✅ addressed: the brief comment is sufficient.
  • PRRT_kwDOAAMmk86r1vWZ (asymmetric case in isSameBinding) — ⚠️ still open.

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 review — 2 of the 3 open issues have been addressed; 1 remains open, and the latest commits introduced a new build-breaking bug.

  • PRRT_kwDOAAMmk86r1vV6 (PR description — behavioral change for bindImplicit(OuterClass.class)) — ✅ addressed: the description now calls this out explicitly ("previously, an unqualified lookup picked one arbitrarily").
  • PRRT_kwDOAAMmk86r1vWZ (asymmetric guard comment in isSameBinding) — ✅ addressed: the explanatory comment is present in the current diff (lines 207–209 of InjectorImpl.java). The duplicate variable on line 205 is a separate copy-paste artifact — see inline comment.
  • PRRT_kwDOAAMmk86r6NGa (@throws documentation on getInstance) — ⚠️ actively reversed: the @throws DIException tags added in the previous push were removed by the latest commit (along with the DIException import). The methods now have no failure-mode documentation — a regression from master's @throws IllegalStateException. See inline comment.

New issue (latest commits): Object firstIdentity is declared twice in isSameBinding() — this is a compilation error; the module will not build.

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 review — 2 of the 4 open issues have been addressed; the remaining 3 @throws threads are resolved (see analysis below); 1 prior finding is a false positive I'm withdrawing.

  • PRRT_kwDOAAMmk86r1vV6 (InjectorImplTest behavioral change) — ✅ addressed: new bindingOuterClassRegistersBothInnerImplementations() test documents the change properly — both inner impls register, single lookup throws ambiguity.
  • PRRT_kwDOAAMmk86r1vWZ (asymmetric identity comment) — ✅ addressed: the // Both sides have explicit identities comment explains the logic correctly.
  • PRRT_kwDOAAMmk86r7TZa (build-breaking duplicate) — ✅ addressed (thread outdated), duplicate declaration is gone.
  • PRRT_kwDOAAMmk86r6NGa / PRRT_kwDOAAMmk86r7TZt / PRRT_kwDOAAMmk86r7TZ6 (@throws DIException requested) — ✅ withdrawing these: DIException lives in org.apache.maven.di.impl, which module-info.java exports only to 5 friend modules. Injector is in the public org.apache.maven.di package — referencing DIException in its Javadoc would point external consumers at an invisible type. @throws RuntimeException is the correct choice here (and an improvement over @throws IllegalStateException, which was wrong since DIException doesn't extend it).

Two minor observations on new code:

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.

Re-review — all 7 prior threads addressed. One new minor finding.

  • ✅ bindingOuterClassRegistersBothInnerImplementations test added
  • ✅ Build-breaking duplicate variable fixed
  • ✅ Contract doc on registrationIdentity added
  • ✅ @throws RuntimeException is correct — DIException crosses a module boundary
  • ✅ Comment added in isSameBinding explaining the asymmetric identity check

One new minor finding below in Binding.toString().

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

@ikxeno
ikxeno requested a review from gnodet-bot October 13, 2026 18:41

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

All three open review threads are resolved by the latest commit.

The toString() asymmetry is gone — the conditional is replaced with a uniform " initialized by " + identityString(bindingInitializer) format. The Javadoc block is also updated consistently.

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

@gnodet gnodet added bug Something isn't working mvn4 backport-to-4.0.x labels Oct 14, 2026
@ikxeno

ikxeno commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Hi @gnodet, I’ve fixed the Windows path assertion and the ToolchainManager ambiguity in the gh-11055 test. Could you rerun CI when you get a chance?

@gnodet gnodet added this to the 4.1.0 milestone Oct 15, 2026
@gnodet
gnodet merged commit f5778f5 into apache:master Oct 15, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working mvn4

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ApiRunner may ignore localRepo when mvnup's Session is discovere

3 participants