Skip to content

Commit 79b786c

Browse files
authored
fix the error message for instance methods that don't exist (#76512) (#76566)
This fixes the error message in Painless for when an instance-style method isn't found. It now prints the number of arguments instead of the memory location of the nodes data structure.
1 parent 88cd791 commit 79b786c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/DefaultSemanticAnalysisPhase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,7 @@ public void visitCallLocal(ECallLocal userCallLocalNode, SemanticScope semanticS
17691769

17701770
if (instanceBinding == null) {
17711771
throw userCallLocalNode.createError(new IllegalArgumentException(
1772-
"Unknown call [" + methodName + "] with [" + userArgumentNodes + "] arguments."));
1772+
"Unknown call [" + methodName + "] with [" + userArgumentsSize + "] arguments."));
17731773
}
17741774
}
17751775
}

modules/lang-painless/src/test/java/org/elasticsearch/painless/WhenThingsGoWrongTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,4 +850,11 @@ public void testInvalidNullSafeBehavior() {
850850
exec("def test = ['hostname': 'somehostname']; test?.hostname && params.host.hostname != ''"));
851851
expectScriptThrows(NullPointerException.class, () -> exec("params?.host?.hostname && params.host?.hostname != ''"));
852852
}
853+
854+
public void testInstanceMethodNotFound() {
855+
IllegalArgumentException iae = expectScriptThrows(IllegalArgumentException.class, () -> exec("doesNotExist()"));
856+
assertEquals(iae.getMessage(), "Unknown call [doesNotExist] with [0] arguments.");
857+
iae = expectScriptThrows(IllegalArgumentException.class, () -> exec("doesNotExist(1, 'string', false)"));
858+
assertEquals(iae.getMessage(), "Unknown call [doesNotExist] with [3] arguments.");
859+
}
853860
}

0 commit comments

Comments
 (0)