Skip to content

SpEL chooses wrong method to invoke when varargs method is present [SPR-12803] #17400

@spring-projects-issues

Description

@spring-projects-issues

Lior Lipshitz opened SPR-12803 and commented

I'm trying to evaluate the following SpEL expression:

T(com.google.common.collect.Lists).newArrayList(#iterable)
where #iterable is of type java.lang.Iterable. Google Guava com.google.common.collect.Lists (version 14.0) does have a method newArrayList(Iterable) but for some reason SpEL chooses to invoke a different method: newArrayList(Object[])

The issue seems to be with org.springframework.expression.spel.support.ReflectiveMethodResolver implementation: it seems to be sensitive to the manner in which methods are sorted by the java.lang.Class::getMethods. If 2 methods match the invocation (in the case one of the methods is varargs), the later method (in the order) will be invoked, instead of choosing the method that isn't varargs (which is more specific). It seems like JDK doesn't guarantee the order the methods are sorted: different runs yield different order.


Affects: 3.1.1

Reference URL: http://stackoverflow.com/questions/28924430/spring-spel-chooses-wrong-method-to-invoke

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions