Skip to content

array varargs conversion error in SpEL expression [SPR-11494] #16119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Feb 28, 2014 · 3 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Jacek Obarymski opened SPR-11494 and commented

The following test case (see ):

ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("T(java.util.Arrays).asList('a','b')");
List<String> list = (List<String>) exp.getValue();
assertThat(list.size(), is(2));

throws an exception:

java.lang.IllegalArgumentException: Final expected argument should be array type (the varargs parameter)
	at org.springframework.util.Assert.isTrue(Assert.java:65)
	at org.springframework.expression.spel.support.ReflectionHelper.compareArgumentsVarargs(ReflectionHelper.java:144)
	at org.springframework.expression.spel.support.ReflectiveMethodResolver.resolve(ReflectiveMethodResolver.java:154)
	at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:189)
	at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:118)
	at org.springframework.expression.spel.ast.MethodReference.access$100(MethodReference.java:44)
	at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:258)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:84)
	at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:103)
	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:68)

Affects: 4.0.2

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

Hi,

I have added a repro project with your test and it passes for me. Could you please clarify there the scenario that is failing for you?
https://github.com/spring-projects/spring-framework-issues/tree/master/SPR-11494

Thanks

@spring-projects-issues
Copy link
Collaborator Author

Jacek Obarymski commented

sorry forgot to add:

List<String> list = (List<String>) exp.getValue(); //the exception actually happens here.
assertThat(list.size(), is(2));

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Fixed through falling back to the raw parameter type in the TypeDescriptor(MethodParameter) constructor, properly detecting the vararg array even in case of an unresolvable type variable, and through restoring getElementTypeDescriptor's original behavior for arrays, i.e. always returning a non-null descriptor.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants