Include function name in SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION

Closes gh-32239
This commit is contained in:
Sam Brannen 2024-02-11 13:51:58 +01:00
parent dc2dbd9700
commit f295def2a8
3 changed files with 10 additions and 10 deletions

View File

@ -77,7 +77,7 @@ public enum SpelMessage {
"Cannot compare instances of {0} and {1}"), "Cannot compare instances of {0} and {1}"),
INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION(Kind.ERROR, 1014, INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION(Kind.ERROR, 1014,
"Incorrect number of arguments for function, {0} supplied but function takes {1}"), "Incorrect number of arguments for function ''{0}'': {1} supplied but function takes {2}"),
INVALID_TYPE_FOR_SELECTION(Kind.ERROR, 1015, INVALID_TYPE_FOR_SELECTION(Kind.ERROR, 1015,
"Cannot perform selection on input data of type ''{0}''"), "Cannot perform selection on input data of type ''{0}''"),

View File

@ -121,7 +121,7 @@ public class FunctionReference extends SpelNodeImpl {
int declaredParamCount = method.getParameterCount(); int declaredParamCount = method.getParameterCount();
if (declaredParamCount != functionArgs.length) { if (declaredParamCount != functionArgs.length) {
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
functionArgs.length, declaredParamCount); this.name, functionArgs.length, declaredParamCount);
} }
} }
if (!Modifier.isStatic(method.getModifiers())) { if (!Modifier.isStatic(method.getModifiers())) {
@ -183,7 +183,7 @@ public class FunctionReference extends SpelNodeImpl {
// incorrect number, including more arguments and not a vararg // incorrect number, including more arguments and not a vararg
// perhaps a subset of arguments was provided but the MethodHandle wasn't bound? // perhaps a subset of arguments was provided but the MethodHandle wasn't bound?
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
functionArgs.length, declaredParamCount); this.name, functionArgs.length, declaredParamCount);
} }
// simplest case: the MethodHandle is fully bound or represents a static method with no params: // simplest case: the MethodHandle is fully bound or represents a static method with no params:

View File

@ -48,14 +48,14 @@ class VariableAndFunctionTests extends AbstractExpressionTests {
@Test @Test
void functionInvocationWithIncorrectNumberOfArguments() { void functionInvocationWithIncorrectNumberOfArguments() {
// Method: reverseInt() expects 3 ints // Method: #reverseInt(int, int, int)
evaluateAndCheckError("#reverseInt()", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 0, 3); evaluateAndCheckError("#reverseInt()", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "reverseInt", 0, 3);
evaluateAndCheckError("#reverseInt(1,2)", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 2, 3); evaluateAndCheckError("#reverseInt(1,2)", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "reverseInt", 2, 3);
evaluateAndCheckError("#reverseInt(1,2,3,4)", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 4, 3); evaluateAndCheckError("#reverseInt(1,2,3,4)", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "reverseInt", 4, 3);
// MethodHandle: message() maps to java.lang.String.format(String, Object...) // MethodHandle: #message(template, args...)
evaluateAndCheckError("#message()", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 0, 2); evaluateAndCheckError("#message()", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "message", 0, 2);
evaluateAndCheckError("#message('%s')", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 1, 2); evaluateAndCheckError("#message('%s')", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "message", 1, 2);
} }
@Test @Test