Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 322e7fa

Browse filesBrowse files
authored
Merge pull request #4726 from johannescoetzee/johannes/fix-4722
Fix IndexOutOfBoundsException when resolving calls with varargs
2 parents 72a43fa + 66b3bac commit 322e7fa
Copy full SHA for 322e7fa

File tree

Expand file treeCollapse file tree

2 files changed

+46
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+46
-2
lines changed

‎javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java

Copy file name to clipboardExpand all lines: javaparser-core/src/main/java/com/github/javaparser/resolution/logic/MethodResolutionLogic.java
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,14 +713,22 @@ public static SymbolReference<ResolvedMethodDeclaration> findMostApplicable(
713713

714714
protected static boolean isExactMatch(ResolvedMethodLikeDeclaration method, List<ResolvedType> argumentsTypes) {
715715
for (int i = 0; i < method.getNumberOfParams(); i++) {
716-
if (!method.getParam(i).getType().equals(argumentsTypes.get(i))) {
716+
ResolvedType paramType = getMethodsExplicitAndVariadicParameterType(method, i);
717+
if (paramType == null) {
718+
return false;
719+
}
720+
if (i >= argumentsTypes.size()) {
721+
return false;
722+
}
723+
if (!paramType.equals(argumentsTypes.get(i))) {
717724
return false;
718725
}
719726
}
720727
return true;
721728
}
722729

723-
private static ResolvedType getMethodsExplicitAndVariadicParameterType(ResolvedMethodDeclaration method, int i) {
730+
private static ResolvedType getMethodsExplicitAndVariadicParameterType(
731+
ResolvedMethodLikeDeclaration method, int i) {
724732
int numberOfParams = method.getNumberOfParams();
725733
if (i < numberOfParams) {
726734
return method.getParam(i).getType();
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.javaparser.symbolsolver;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import com.github.javaparser.ParserConfiguration;
6+
import com.github.javaparser.StaticJavaParser;
7+
import com.github.javaparser.ast.CompilationUnit;
8+
import com.github.javaparser.ast.expr.MethodCallExpr;
9+
import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
10+
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
11+
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
12+
import org.junit.jupiter.api.Test;
13+
14+
public class Issue4722Test {
15+
@Test
16+
void test() {
17+
String code = "public class Test {\n" + " void test(String s, Object... objects) { }\n"
18+
+ " void test(String s, String t, Object... objects) { }\n"
19+
+ " void foo() {\n"
20+
+ " test(\"hello\", \"world\");\n"
21+
+ " }\n"
22+
+ "}";
23+
24+
ParserConfiguration configuration = new ParserConfiguration()
25+
.setSymbolResolver(new JavaSymbolSolver(new CombinedTypeSolver(new ReflectionTypeSolver())));
26+
StaticJavaParser.setConfiguration(configuration);
27+
28+
CompilationUnit cu = StaticJavaParser.parse(code);
29+
30+
MethodCallExpr call = cu.findFirst(MethodCallExpr.class).get();
31+
ResolvedMethodDeclaration resolvedMethod = call.resolve();
32+
assertEquals(
33+
"Test.test(java.lang.String, java.lang.String, java.lang.Object...)",
34+
resolvedMethod.getQualifiedSignature());
35+
}
36+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.