10BC0 Fix IndexOutOfBoundsException resulting from empty varargs call as method usage by johannescoetzee · Pull Request #4754 · javaparser/javaparser · GitHub
[go: up one dir, main page]

Skip to content

Conversation

johannescoetzee
Copy link
Contributor

This PR fixes a crash due to java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 0 when attempting to resolve a call to a method with only a single variadic parameter while providing no arguments, for example the foo call in:

public class Test {
  static String foo(String... values) { return null; }
  static void id(String value) { return null; }

  void test() {
    id(foo());
  }
}

This crash only occurs when attempting to resolve it via the MethodUsage code path, which is why the foo call is used as an argument to the id call. For the unit test, including all the code in the test code string didn't trigger this path either, so I added a test jar to be able to test this properly, along with the source and class file used to create the jar.

The fix is to check whether the argument list is empty (and return if it is) before attempting to match/replace type parameters using the actual argument types.

Copy link
codecov bot commented May 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 58.321%. Comparing base (fd89ae0) to head (ab4e404).
Report is 5 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##              master     #4754       +/-   ##
===============================================
+ Coverage     58.319%   58.321%   +0.002%     
- Complexity      2511      2512        +1     
===============================================
  Files            671       671               
  Lines          38778     38780        +2     
  Branches        7039      7040        +1     
===============================================
+ Hits           22615     22617        +2     
  Misses         13271     13271               
  Partials        2892      2892               
Flag Coverage Δ
AlsoSlowTests 58.321% <100.000%> (+0.002%) ⬆️
javaparser-core 58.321% <100.000%> (+0.002%) ⬆️
javaparser-symbol-solver 58.321% <100.000%> (+0.002%) ⬆️
jdk-10 57.862% <100.000%> (+0.002%) ⬆️
jdk-11 57.871% <100.000%> (+0.002%) ⬆️
jdk-12 57.861% <100.000%> (+0.002%) ⬆️
jdk-13 57.871% <100.000%> (+0.002%) ⬆️
jdk-14 58.108% <100.000%> (+0.002%) ⬆️
jdk-15 58.119% <100.000%> (+0.002%) ⬆️
jdk-16 58.093% <100.000%> (+0.002%) ⬆️
jdk-17 58.248% <100.000%> (+0.002%) ⬆️
jdk-18 58.248% <100.000%> (+0.002%) ⬆️
jdk-8 57.873% <100.000%> (+0.002%) ⬆️
jdk-9 57.862% <100.000%> (+0.002%) ⬆️
macos-latest 58.313% <100.000%> (+0.002%) ⬆️
ubuntu-latest 58.298% <100.000%> (+0.002%) ⬆️
windows-latest 58.303% <100.000%> (+0.002%) ⬆️

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

Files with missing lines Coverage Δ
...avaparsermodel/contexts/MethodCallExprContext.java 84.469% <100.000%> (+0.118%) ⬆️

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 3cf0360...ab4e404. Read the comment docs.

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

// type information about the parameters
if (actualParamTypes.isEmpty()) {
return methodUsage;
} else {
Copy link
Collaborator
@jlerbsc jlerbsc May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the else statement mandatory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not. I've updated the PR to remove it.

@johannescoetzee johannescoetzee force-pushed the johannes/fix-empty-varargs-usage branch from b59b768 to ff3c527 Compare May 16, 2025 12:37
@jlerbsc jlerbsc merged commit bfa3340 into javaparser:master May 17, 2025
35 checks passed
@jlerbsc jlerbsc added this to the next release milestone May 17, 2025
@jlerbsc
Copy link
Collaborator
jlerbsc commented May 17, 2025

Thank you for this PR.

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

0