Skip to content

Commit 48a6bd6

Browse files
committed
Polishing
1 parent e15f123 commit 48a6bd6

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ else if (spelParamCount == declaredParamCount) {
240240
// to be packaged in an array, in contrast to how method invocation works with
241241
// reflection.
242242
int actualVarargsIndex = functionArgs.length - 1;
243-
if (actualVarargsIndex >= 0 && functionArgs[actualVarargsIndex].getClass().isArray()) {
244-
Object[] argsToUnpack = (Object[]) functionArgs[actualVarargsIndex];
243+
if (actualVarargsIndex >= 0 && functionArgs[actualVarargsIndex] instanceof Object[] argsToUnpack) {
245244
Object[] newArgs = new Object[actualVarargsIndex + argsToUnpack.length];
246245
System.arraycopy(functionArgs, 0, newArgs, 0, actualVarargsIndex);
247246
System.arraycopy(argsToUnpack, 0, newArgs, actualVarargsIndex, argsToUnpack.length);

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ static boolean convertArguments(TypeConverter converter, Object[] arguments, Exe
279279
for (int i = 0; i < arguments.length; i++) {
280280
TypeDescriptor targetType = new TypeDescriptor(MethodParameter.forExecutable(executable, i));
281281
Object argument = arguments[i];
282-
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
282+
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
283+
arguments[i] = converter.convertValue(argument, sourceType, targetType);
283284
conversionOccurred |= (argument != arguments[i]);
284285
}
285286
}
@@ -288,7 +289,8 @@ static boolean convertArguments(TypeConverter converter, Object[] arguments, Exe
288289
for (int i = 0; i < varargsPosition; i++) {
289290
TypeDescriptor targetType = new TypeDescriptor(MethodParameter.forExecutable(executable, i));
290291
Object argument = arguments[i];
291-
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
292+
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
293+
arguments[i] = converter.convertValue(argument, sourceType, targetType);
292294
conversionOccurred |= (argument != arguments[i]);
293295
}
294296

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

366368
Object argument = arguments[i];
367-
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
369+
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
370+
arguments[i] = converter.convertValue(argument, sourceType, targetType);
368371
conversionOccurred |= (argument != arguments[i]);
369372
}
370373
}
@@ -376,7 +379,8 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O
376379
TypeDescriptor targetType = new TypeDescriptor(resolvableType, argumentClass, null);
377380

378381
Object argument = arguments[i];
379-
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
382+
TypeDescriptor sourceType = TypeDescriptor.forObject(argument);
383+
arguments[i] = converter.convertValue(argument, sourceType, targetType);
380384
conversionOccurred |= (argument != arguments[i]);
381385
}
382386

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

0 commit comments

Comments
 (0)