dimanche 8 mars 2015

Spring SpEL method invocation error on OpenJdk

I'm trying to evaluate the following SpEL expression (Spring-expression version 3.1.1):



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[])


This issue only happens when running with OpenJdk 7 (on Linux), not when running with Oracle JDK. I dived into the code and found the issue 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. In the case above, it turns out that OpenJDK will output the method list in a different order then Oracle JDK will: 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).


Is there a way to overcome this issue?


Aucun commentaire:

Enregistrer un commentaire