From dc16f3cffb32ea6574f5d33c6d2c6d280b37671a Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:01:58 +0200 Subject: [PATCH] Polish SpEL function invocation support --- .../expression/spel/ast/FunctionReference.java | 2 +- .../spel/support/ReflectionHelper.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java index 9f715e29870b..22206f4bcb28 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java @@ -217,7 +217,7 @@ else if (spelParamCount != declaredParamCount) { } } - // more complex case, we need to look at conversion and vararg repacking + // more complex case, we need to look at conversion and varargs repackaging Integer varArgPosition = null; if (isSuspectedVarargs) { varArgPosition = declaredParamCount - 1; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java index 31bd84389a29..44426fcb317b 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java @@ -356,10 +356,10 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O MethodHandle methodHandle, @Nullable Integer varargsPosition) throws EvaluationException { boolean conversionOccurred = false; - MethodType methodHandleArgumentTypes = methodHandle.type(); + MethodType methodHandleType = methodHandle.type(); if (varargsPosition == null) { for (int i = 0; i < arguments.length; i++) { - Class argumentClass = methodHandleArgumentTypes.parameterType(i); + Class argumentClass = methodHandleType.parameterType(i); ResolvableType resolvableType = ResolvableType.forClass(argumentClass); TypeDescriptor targetType = new TypeDescriptor(resolvableType, argumentClass, null); @@ -371,7 +371,7 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O else { // Convert everything up to the varargs position for (int i = 0; i < varargsPosition; i++) { - Class argumentClass = methodHandleArgumentTypes.parameterType(i); + Class argumentClass = methodHandleType.parameterType(i); ResolvableType resolvableType = ResolvableType.forClass(argumentClass); TypeDescriptor targetType = new TypeDescriptor(resolvableType, argumentClass, null); @@ -380,10 +380,10 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O conversionOccurred |= (argument != arguments[i]); } - Class varArgClass = methodHandleArgumentTypes.lastParameterType().componentType(); + Class varArgClass = methodHandleType.lastParameterType().componentType(); ResolvableType varArgResolvableType = ResolvableType.forClass(varArgClass); - TypeDescriptor varArgComponentType = new TypeDescriptor(varArgResolvableType, varArgClass, null); - TypeDescriptor componentTypeDesc = varArgComponentType.getElementTypeDescriptor(); + TypeDescriptor targetType = new TypeDescriptor(varArgResolvableType, varArgClass, null); + TypeDescriptor componentTypeDesc = targetType.getElementTypeDescriptor(); // TODO Determine why componentTypeDesc can be null. // Assert.state(componentTypeDesc != null, "Component type must not be null for a varargs array"); @@ -403,7 +403,7 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O // convert a String containing a comma would result in the String being split and // repackaged in an array when it should be used as-is. else if (componentTypeDesc != null && !sourceType.isAssignableTo(componentTypeDesc)) { - arguments[varargsPosition] = converter.convertValue(argument, sourceType, varArgComponentType); + arguments[varargsPosition] = converter.convertValue(argument, sourceType, targetType); } // Possible outcomes of the above if-else block: // 1) the input argument was null, and nothing was done. @@ -420,7 +420,7 @@ else if (componentTypeDesc != null && !sourceType.isAssignableTo(componentTypeDe else { for (int i = varargsPosition; i < arguments.length; i++) { Object argument = arguments[i]; - arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), varArgComponentType); + arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType); conversionOccurred |= (argument != arguments[i]); } }