Skip to content

Commit f295def

Browse files
committed
Include function name in SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION
Closes gh-32239
1 parent dc2dbd9 commit f295def

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public enum SpelMessage {
7777
"Cannot compare instances of {0} and {1}"),
7878

7979
INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION(Kind.ERROR, 1014,
80-
"Incorrect number of arguments for function, {0} supplied but function takes {1}"),
80+
"Incorrect number of arguments for function ''{0}'': {1} supplied but function takes {2}"),
8181

8282
INVALID_TYPE_FOR_SELECTION(Kind.ERROR, 1015,
8383
"Cannot perform selection on input data of type ''{0}''"),

spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private TypedValue executeFunctionViaMethod(ExpressionState state, Method method
121121
int declaredParamCount = method.getParameterCount();
122122
if (declaredParamCount != functionArgs.length) {
123123
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
124-
functionArgs.length, declaredParamCount);
124+
this.name, functionArgs.length, declaredParamCount);
125125
}
126126
}
127127
if (!Modifier.isStatic(method.getModifiers())) {
@@ -183,7 +183,7 @@ private TypedValue executeFunctionViaMethodHandle(ExpressionState state, MethodH
183183
// incorrect number, including more arguments and not a vararg
184184
// perhaps a subset of arguments was provided but the MethodHandle wasn't bound?
185185
throw new SpelEvaluationException(SpelMessage.INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION,
186-
functionArgs.length, declaredParamCount);
186+
this.name, functionArgs.length, declaredParamCount);
187187
}
188188

189189
// simplest case: the MethodHandle is fully bound or represents a static method with no params:

spring-expression/src/test/java/org/springframework/expression/spel/VariableAndFunctionTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ void variableAccessWithWellKnownVariables() {
4848

4949
@Test
5050
void functionInvocationWithIncorrectNumberOfArguments() {
51-
// Method: reverseInt() expects 3 ints
52-
evaluateAndCheckError("#reverseInt()", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 0, 3);
53-
evaluateAndCheckError("#reverseInt(1,2)", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 2, 3);
54-
evaluateAndCheckError("#reverseInt(1,2,3,4)", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 4, 3);
55-
56-
// MethodHandle: message() maps to java.lang.String.format(String, Object...)
57-
evaluateAndCheckError("#message()", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 0, 2);
58-
evaluateAndCheckError("#message('%s')", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, 1, 2);
51+
// Method: #reverseInt(int, int, int)
52+
evaluateAndCheckError("#reverseInt()", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "reverseInt", 0, 3);
53+
evaluateAndCheckError("#reverseInt(1,2)", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "reverseInt", 2, 3);
54+
evaluateAndCheckError("#reverseInt(1,2,3,4)", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "reverseInt", 4, 3);
55+
56+
// MethodHandle: #message(template, args...)
57+
evaluateAndCheckError("#message()", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "message", 0, 2);
58+
evaluateAndCheckError("#message('%s')", INCORRECT_NUMBER_OF_ARGUMENTS_TO_FUNCTION, 0, "message", 1, 2);
5959
}
6060

6161
@Test

0 commit comments

Comments
 (0)