Repository navigation
Fix #13469: prefer default bindings for unqualified lookups - #13471
Conversation
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.
This comment has been minimized.
This comment has been minimized.
gnodet-bot
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 newbindingOuterClassRegistersBothInnerImplementations()test validates the ambiguity detection, which is good. The PR description still does not call out this as a breaking change for callers ofbindImplicit(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 (
@throwsinInjector) —⚠️ evolved: the@throws IllegalStateExceptionwas removed, but no replacement@throwswas 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.
Co-authored-by: Guillaume Nodet - AI Bot <[email protected]>
gnodet-bot
left a comment
There was a problem hiding this comment.
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 ofInjectorImpl.java). The duplicate variable on line 205 is a separate copy-paste artifact — see inline comment. - PRRT_kwDOAAMmk86r6NGa (
@throwsdocumentation ongetInstance) —⚠️ actively reversed: the@throws DIExceptiontags added in the previous push were removed by the latest commit (along with theDIExceptionimport). 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
left a comment
There was a problem hiding this comment.
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 identitiescomment explains the logic correctly. - PRRT_kwDOAAMmk86r7TZa (build-breaking duplicate) — ✅ addressed (thread outdated), duplicate declaration is gone.
- PRRT_kwDOAAMmk86r6NGa / PRRT_kwDOAAMmk86r7TZt / PRRT_kwDOAAMmk86r7TZ6 (
@throws DIExceptionrequested) — ✅ withdrawing these:DIExceptionlives inorg.apache.maven.di.impl, whichmodule-info.javaexports only to 5 friend modules.Injectoris in the publicorg.apache.maven.dipackage — referencingDIExceptionin its Javadoc would point external consumers at an invisible type.@throws RuntimeExceptionis the correct choice here (and an improvement over@throws IllegalStateException, which was wrong sinceDIExceptiondoesn'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
left a comment
There was a problem hiding this comment.
Re-review — all 7 prior threads addressed. One new minor finding.
- ✅
bindingOuterClassRegistersBothInnerImplementationstest added - ✅ Build-breaking duplicate variable fixed
- ✅ Contract doc on
registrationIdentityadded - ✅
@throws RuntimeExceptionis correct —DIExceptioncrosses a module boundary - ✅ Comment added in
isSameBindingexplaining 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.
gnodet-bot
left a comment
There was a problem hiding this comment.
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.
Fixes #13469.
I ran into this while working on
mvnval. WhenApiRunnerrequests an unqualifiedSession, 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,ApiRunnerloses 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 throughList<T>andMap<String, T>injection.I added tests for these cases, including an
ApiRunnertest with the namedSessionregistered first. Themvnvaltests 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).