Skip to content

Commit 74b0bb1

Browse files
committed
Merge branch '6.1.x'
2 parents 46a4ad4 + 8badae9 commit 74b0bb1

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,15 @@ static boolean convertArguments(TypeConverter converter, Object[] arguments, Exe
310310
}
311311
}
312312
// If the argument type is assignable to the varargs component type, there is no need to
313-
// convert it or wrap it in an array. For example, using StringToArrayConverter to
314-
// convert a String containing a comma would result in the String being split and
315-
// repackaged in an array when it should be used as-is.
316-
else if (!sourceType.isAssignableTo(componentTypeDesc)) {
317-
arguments[varargsPosition] = converter.convertValue(argument, sourceType, targetType);
313+
// convert it or wrap it in an array. For example, using StringToArrayConverter to convert
314+
// a String containing a comma would result in the String being split and repackaged in an
315+
// array when it should be used as-is. Similarly, if the argument is an array that is
316+
// assignable to the varargs array type, there is no need to convert it.
317+
else if (!sourceType.isAssignableTo(componentTypeDesc) ||
318+
(sourceType.isArray() && !sourceType.isAssignableTo(targetType))) {
319+
320+
TypeDescriptor targetTypeToUse = (sourceType.isArray() ? targetType : componentTypeDesc);
321+
arguments[varargsPosition] = converter.convertValue(argument, sourceType, targetTypeToUse);
318322
}
319323
// Possible outcomes of the above if-else block:
320324
// 1) the input argument was null, and nothing was done.

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

-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.ArrayList;
2424
import java.util.List;
2525

26-
import org.junit.jupiter.api.Disabled;
2726
import org.junit.jupiter.api.Test;
2827

2928
import org.springframework.expression.Expression;
@@ -357,7 +356,6 @@ void testVarargsWithPrimitiveArrayType() {
357356
evaluate("formatPrimitiveVarargs('x -> %s %s', '2', 3.0d)", "x -> 2 3", String.class);
358357
}
359358

360-
@Disabled("Primitive array to Object[] conversion is not currently supported")
361359
@Test
362360
void testVarargsWithPrimitiveArrayToObjectArrayConversion() {
363361
evaluate("formatObjectVarargs('x -> %s %s %s', new short[]{1, 2, 3})", "x -> 1 2 3", String.class); // short[] to Object[]

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

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.expression.spel;
1818

19-
import org.junit.jupiter.api.Disabled;
2019
import org.junit.jupiter.api.Test;
2120

2221
import org.springframework.expression.spel.standard.SpelExpressionParser;
@@ -199,7 +198,6 @@ void functionWithPrimitiveVarargsViaMethodHandle() {
199198
evaluate("#formatPrimitiveVarargs('x -> %s %s %s', new String[]{'1', '2', '3'})", "x -> 1 2 3", String.class); // String[] to int[]
200199
}
201200

202-
@Disabled("Primitive array to Object[] conversion is not currently supported")
203201
@Test
204202
void functionFromMethodWithVarargsAndPrimitiveArrayToObjectArrayConversion() {
205203
evaluate("#varargsObjectFunction(new short[]{1, 2, 3})", "[1, 2, 3]", String.class); // short[] to Object[]

0 commit comments

Comments
 (0)