SpringSource/spring-framework — pull request #329 by sleepred (2013-08-02 04:06:17+00:00)
Title: Fix array varargs conversion error in SpEL expression

Array varargs convert failed SpEL Expression ( Arrays.asList etc )

That is,

// sucess
List list1 = Arrays.asList(new String[]{a"",""});
assertEquals(2, stringlist.size()); // return 2

// error
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("T(java.util.Arrays).asList(new
String[]{'a','b'})");
List list2= (List) exp.getValue();
assertEquals(2, list2= .size()); // return 1

So, Add arrary varargs checking in ReflectiveMethodExecutor#execute

...

if (this.method.isVarArgs()) {
// no arguments
// Calling 'public int aVarargsMethod(String... strings)'
// evaluate 'aVarargsMethod()'
if (arguments.length == 0) {
arguments =
ReflectionHelper.setupArgumentsForVarargsInvocation(this.method.getParameterTypes(),
arguments);
}
else {

Class lastArgumentType = arguments[arguments.length-1].getClass();
int varargsCount = arguments.length - this.varargsPosition;

// Calling 'public static List asList(T... a)'
// check array varargs => T(java.util.Arrays).asList(new
String[]{'a','b'});
// and check varargsCount => T(java.util.Arrays).asList(new
Integer[]{1,2}, new Integer[]{1,2} )
if(!lastArgumentType.isArray() || varargsCount > 1) {
arguments =
ReflectionHelper.setupArgumentsForVarargsInvocation(this.method.getParameterTypes(),
arguments);
}
}
}
...

thanks

Issue: SPR-10781