Skip to content

Fix MethodUtils.getMatchingMethod false ambiguity on boxed arguments#1727

Merged
garydgregory merged 1 commit into
apache:masterfrom
alhudz:matching-method-boxing-distance
Jun 23, 2026
Merged

Fix MethodUtils.getMatchingMethod false ambiguity on boxed arguments#1727
garydgregory merged 1 commit into
apache:masterfrom
alhudz:matching-method-boxing-distance

Conversation

@alhudz

@alhudz alhudz commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

MethodUtils.getMatchingMethod ranks overloads with the private distance helper, which charges a flat +1 for any autoboxing conversion. For a primitive argument that makes int to Integer and int to Number both score 1, so when a class declares both f(Integer) and f(Number) the call getMatchingMethod(cls, "f", int.class) puts two candidates in the same distance bucket and throws IllegalStateException: Found multiple candidates, even though javac resolves f(someInt) unambiguously to f(Integer).

The fix keeps the flat penalty when a primitive boxes to its exact wrapper but adds the supertype cost when it boxes to a supertype, so int to Integer ranks strictly below int to Number. distance is private to getMatchingMethod, so the change stays inside that resolver; the auto-unboxing direction and every existing resolution are unaffected.

@garydgregory garydgregory changed the title fix MethodUtils.getMatchingMethod false ambiguity on boxed arguments Fix MethodUtils.getMatchingMethod false ambiguity on boxed arguments Jun 23, 2026
@garydgregory garydgregory merged commit aae7f0e into apache:master Jun 23, 2026
20 of 21 checks passed
@garydgregory

Copy link
Copy Markdown
Member

Thank you @alhudz , now merged 🚀 and deployed to snapshot builds in https://repository.apache.org/content/repositories/snapshots/org/apache/commons/commons-lang3/3.21.0-SNAPSHOT/

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants