Skip to content

Fix MethodAmbiguityException for methods with varargs#4725

Merged
jlerbsc merged 1 commit into
javaparser:masterfrom
johannescoetzee:johannes/fix-4710
Apr 11, 2025
Merged

Fix MethodAmbiguityException for methods with varargs#4725
jlerbsc merged 1 commit into
javaparser:masterfrom
johannescoetzee:johannes/fix-4710

Conversation

@johannescoetzee

@johannescoetzee johannescoetzee commented Apr 11, 2025

Copy link
Copy Markdown
Collaborator

Fixes #4723
Should fix #4710

It turns out both of these issues did share a root cause after all. The issue is that the specific case of 2 methods with varargs wasn't handled by any of the existing checks for different reasons:

  • There was already a check whether methodB has varargs while methodA does not, in which case methodA is more specific.
  • There is a check to see if parameterTypeB is assignable by parameterTypeA and vice-versa which can be used to determine which method is more specific, but this doesn't apply for varags since the vararg is an array type. For example, String is assignable to Object, but not to Object... since the latter is an array and a String is not an array.

To fix this I added an explicit check for this. If parameterTypeB is variadic and parameterTypeA is not, then methodA must have the more specific signature (since both methods must be applicable to get this far into the logic).

@codecov

codecov Bot commented Apr 11, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 58.280%. Comparing base (f6f62aa) to head (b8feaa5).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...parser/resolution/logic/MethodResolutionLogic.java 0.000% 5 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##              master     #4725       +/-   ##
===============================================
- Coverage     58.287%   58.280%   -0.008%     
  Complexity      2511      2511               
===============================================
  Files            671       671               
  Lines          38768     38773        +5     
  Branches        7034      7036        +2     
===============================================
  Hits           22597     22597               
- Misses         13278     13283        +5     
  Partials        2893      2893               
Flag Coverage Δ
AlsoSlowTests 58.280% <0.000%> (-0.008%) ⬇️
javaparser-core 58.280% <0.000%> (-0.008%) ⬇️
javaparser-symbol-solver 58.280% <0.000%> (-0.008%) ⬇️
jdk-10 57.831% <0.000%> (-0.008%) ⬇️
jdk-11 57.830% <0.000%> (-0.008%) ⬇️
jdk-12 57.830% <0.000%> (-0.008%) ⬇️
jdk-13 57.830% <0.000%> (-0.008%) ⬇️
jdk-14 58.077% <0.000%> (-0.008%) ⬇️
jdk-15 58.077% <0.000%> (-0.008%) ⬇️
jdk-16 58.052% <0.000%> (-0.008%) ⬇️
jdk-17 58.206% <0.000%> (-0.008%) ⬇️
jdk-18 58.206% <0.000%> (-0.008%) ⬇️
jdk-8 57.832% <0.000%> (-0.008%) ⬇️
jdk-9 57.828% <0.000%> (-0.008%) ⬇️
macos-latest 58.272% <0.000%> (-0.008%) ⬇️
ubuntu-latest 58.267% <0.000%> (-0.008%) ⬇️
windows-latest 58.262% <0.000%> (-0.008%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...parser/resolution/logic/MethodResolutionLogic.java 0.000% <0.000%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd84967...b8feaa5. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johannescoetzee

Copy link
Copy Markdown
Collaborator Author

I don't understand why the codecov check is failing. I've confirmed that commenting out the lines it claims aren't covered causes the tests to fail, so I guess it's a bug

@jlerbsc jlerbsc merged commit 72a43fa into javaparser:master Apr 11, 2025
@jlerbsc

jlerbsc commented Apr 11, 2025

Copy link
Copy Markdown
Collaborator

Thank you for this contribution.

@jlerbsc jlerbsc added this to the next release milestone Apr 11, 2025
@johannescoetzee johannescoetzee deleted the johannes/fix-4710 branch April 11, 2025 15:23
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.

MethodAmbiguityException when resolving unboxed type MethodAmbiguityException Error while resolving a specific method call using JavaParser

2 participants