Skip to content

Commit c935988

Browse files
committed
Merge branch '6.1.x'
2 parents a421fc4 + 48a6bd6 commit c935988

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ else if (spelParamCount == declaredParamCount) {
243243
// to be packaged in an array, in contrast to how method invocation works with
244244
// reflection.
245245
int actualVarargsIndex = functionArgs.length - 1;
246-
if (actualVarargsIndex >= 0 && functionArgs[actualVarargsIndex].getClass().isArray()) {
247-
Object[] argsToUnpack = (Object[]) functionArgs[actualVarargsIndex];
246+
if (actualVarargsIndex >= 0 && functionArgs[actualVarargsIndex] instanceof Object[] argsToUnpack) {
248247
Object[] newArgs = new Object[actualVarargsIndex + argsToUnpack.length];
249248
System.arraycopy(functionArgs, 0, newArgs, 0, actualVarargsIndex);
250249
System.arraycopy(argsToUnpack, 0, newArgs, actualVarargsIndex, argsToUnpack.length);

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ static boolean convertArguments(TypeConverter converter, Object[] arguments, Exe
278278
for (int i = 0; i < arguments.length; i++) {
279279
TypeDescriptor targetType = new TypeDescriptor(MethodParameter.forExecutable(executable, i));
280280
Object argument = arguments[i];
281-
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
281+
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
282+
arguments[i] = converter.convertValue(argument, sourceType, targetType);
282283
conversionOccurred |= (argument != arguments[i]);
283284
}
284285
}
@@ -287,7 +288,8 @@ static boolean convertArguments(TypeConverter converter, Object[] arguments, Exe
287288
for (int i = 0; i < varargsPosition; i++) {
288289
TypeDescriptor targetType = new TypeDescriptor(MethodParameter.forExecutable(executable, i));
289290
Object argument = arguments[i];
290-
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
291+
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
292+
arguments[i] = converter.convertValue(argument, sourceType, targetType);
291293
conversionOccurred |= (argument != arguments[i]);
292294
}
293295

@@ -317,7 +319,7 @@ else if (!sourceType.isAssignableTo(componentTypeDesc)) {
317319
// Possible outcomes of the above if-else block:
318320
// 1) the input argument was null, and nothing was done.
319321
// 2) the input argument was null; the varargs component type is Optional; and the argument was converted to Optional.empty().
320-
// 3) the input argument was correct type but not wrapped in an array, and nothing was done.
322+
// 3) the input argument was the correct type but not wrapped in an array, and nothing was done.
321323
// 4) the input argument was already compatible (i.e., array of valid type), and nothing was done.
322324
// 5) the input argument was the wrong type and got converted and wrapped in an array.
323325
if (argument != arguments[varargsPosition] &&
@@ -363,7 +365,8 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O
363365
TypeDescriptor targetType = new TypeDescriptor(resolvableType, argumentClass, null);
364366

365367
Object argument = arguments[i];
366-
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
368+
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
369+
arguments[i] = converter.convertValue(argument, sourceType, targetType);
367370
conversionOccurred |= (argument != arguments[i]);
368371
}
369372
}
@@ -375,7 +378,8 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O
375378
TypeDescriptor targetType = new TypeDescriptor(resolvableType, argumentClass, null);
376379

377380
Object argument = arguments[i];
378-
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
381+
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
382+
arguments[i] = converter.convertValue(argument, sourceType, targetType);
379383
conversionOccurred |= (argument != arguments[i]);
380384
}
381385

@@ -406,9 +410,9 @@ else if (!sourceType.isAssignableTo(componentTypeDesc)) {
406410
// Possible outcomes of the above if-else block:
407411
// 1) the input argument was null, and nothing was done.
408412
// 2) the input argument was null; the varargs component type is Optional; and the argument was converted to Optional.empty().
409-
// 3) the input argument was correct type but not wrapped in an array, and nothing was done.
410-
// 4) the input argument was already compatible (i.e., array of valid type), and nothing was done.
411-
// 5) the input argument was the wrong type and got converted and wrapped in an array.
413+
// 3) the input argument was the correct type but not wrapped in an array, and nothing was done.
414+
// 4) the input argument was already compatible (i.e., an Object array of valid type), and nothing was done.
415+
// 5) the input argument was the wrong type and got converted as explained in the comments above.
412416
if (argument != arguments[varargsPosition] &&
413417
!isFirstEntryInArray(argument, arguments[varargsPosition])) {
414418
conversionOccurred = true; // case 5
@@ -418,7 +422,8 @@ else if (!sourceType.isAssignableTo(componentTypeDesc)) {
418422
else {
419423
for (int i = varargsPosition; i < arguments.length; i++) {
420424
Object argument = arguments[i];
421-
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), componentTypeDesc);
425+
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
426+
arguments[i] = converter.convertValue(argument, sourceType, componentTypeDesc);
422427
conversionOccurred |= (argument != arguments[i]);
423428
}
424429
}

0 commit comments

Comments
 (0)