You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
I'm going to have a look at this against the latest 4.2 version of the code, making sure that we reliably choose direct matches over varargs matches. Depending on the impact on the code, this is likely to be backported to 4.1.6 in about two weeks.
In general, please make sure to report such issues against recent versions of Spring. Support for the 3.1.x line ended years ago; even 3.2.x is about to be end-of-lifed rather soon. That said, if this issue turns out to be easy enough to backport, we can consider making it available in the 3.2.14 release in May as well.
Note that this has been fixed as of Spring Framework 4.1.2 already, through #16931 - a larger SpEL revision which explicitly fixed this case as well (see Andy's comments there).
I'm considering an isolated backport for this specific issue to 3.2.14. Unstable reflection results for such obvious cases are quite unpleasant, after all. And we haven't had any regression reports against 4.1.2's changes in that space, so a backport to 3.2.x should be rather safe.
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:
The text was updated successfully, but these errors were encountered: