Merge branch '6.1.x'
This commit is contained in:
@@ -310,11 +310,15 @@ public abstract class ReflectionHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the argument type is assignable to the varargs component type, there is no need to
|
// If the argument type is assignable to the varargs component type, there is no need to
|
||||||
// convert it or wrap it in an array. For example, using StringToArrayConverter to
|
// convert it or wrap it in an array. For example, using StringToArrayConverter to convert
|
||||||
// convert a String containing a comma would result in the String being split and
|
// a String containing a comma would result in the String being split and repackaged in an
|
||||||
// repackaged in an array when it should be used as-is.
|
// array when it should be used as-is. Similarly, if the argument is an array that is
|
||||||
else if (!sourceType.isAssignableTo(componentTypeDesc)) {
|
// assignable to the varargs array type, there is no need to convert it.
|
||||||
arguments[varargsPosition] = converter.convertValue(argument, sourceType, targetType);
|
else if (!sourceType.isAssignableTo(componentTypeDesc) ||
|
||||||
|
(sourceType.isArray() && !sourceType.isAssignableTo(targetType))) {
|
||||||
|
|
||||||
|
TypeDescriptor targetTypeToUse = (sourceType.isArray() ? targetType : componentTypeDesc);
|
||||||
|
arguments[varargsPosition] = converter.convertValue(argument, sourceType, targetTypeToUse);
|
||||||
}
|
}
|
||||||
// Possible outcomes of the above if-else block:
|
// Possible outcomes of the above if-else block:
|
||||||
// 1) the input argument was null, and nothing was done.
|
// 1) the input argument was null, and nothing was done.
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
@@ -357,7 +356,6 @@ class MethodInvocationTests extends AbstractExpressionTests {
|
|||||||
evaluate("formatPrimitiveVarargs('x -> %s %s', '2', 3.0d)", "x -> 2 3", String.class);
|
evaluate("formatPrimitiveVarargs('x -> %s %s', '2', 3.0d)", "x -> 2 3", String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("Primitive array to Object[] conversion is not currently supported")
|
|
||||||
@Test
|
@Test
|
||||||
void testVarargsWithPrimitiveArrayToObjectArrayConversion() {
|
void testVarargsWithPrimitiveArrayToObjectArrayConversion() {
|
||||||
evaluate("formatObjectVarargs('x -> %s %s %s', new short[]{1, 2, 3})", "x -> 1 2 3", String.class); // short[] to Object[]
|
evaluate("formatObjectVarargs('x -> %s %s %s', new short[]{1, 2, 3})", "x -> 1 2 3", String.class); // short[] to Object[]
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.springframework.expression.spel;
|
package org.springframework.expression.spel;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
@@ -199,7 +198,6 @@ class VariableAndFunctionTests extends AbstractExpressionTests {
|
|||||||
evaluate("#formatPrimitiveVarargs('x -> %s %s %s', new String[]{'1', '2', '3'})", "x -> 1 2 3", String.class); // String[] to int[]
|
evaluate("#formatPrimitiveVarargs('x -> %s %s %s', new String[]{'1', '2', '3'})", "x -> 1 2 3", String.class); // String[] to int[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("Primitive array to Object[] conversion is not currently supported")
|
|
||||||
@Test
|
@Test
|
||||||
void functionFromMethodWithVarargsAndPrimitiveArrayToObjectArrayConversion() {
|
void functionFromMethodWithVarargsAndPrimitiveArrayToObjectArrayConversion() {
|
||||||
evaluate("#varargsObjectFunction(new short[]{1, 2, 3})", "[1, 2, 3]", String.class); // short[] to Object[]
|
evaluate("#varargsObjectFunction(new short[]{1, 2, 3})", "[1, 2, 3]", String.class); // short[] to Object[]
|
||||||
|
|||||||
Reference in New Issue
Block a user