Skip to content
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

SpEL: problem with static methods conflicting with instance methods [SPR-12502] #17107

Closed
spring-projects-issues opened this issue Dec 3, 2014 · 5 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 3, 2014

Andy Clement opened SPR-12502 and commented

This problem came up in Spring XD and I think has come up before. Consider this testcode:

public class User {
  public String getName() { return "Andy"; }
}
...
Expression expression = null;
expression = parser.parseExpression("#root.getClass().getName()");
User u = new User();
assertEquals(NamedUser.class.getName(),expression.getValue(u));

The code in ReflectiveMethodResolver.getMethods() tries to ensure static methods are easily callable so merges two sets of candidates together. This causes problems above because the root object User supports getName() but we want to invoke the getName() on the Class object. Now it sometimes works and picks the right one - depending on the JDK you run it on. That variation is due to the ordering of elements from a collection changing across JDKs. No ordering was specified so that isn't unreasonable...

The solution is to change getMethods() - ensure the ordering is fixed by using a LinkedHashSet rather than a HashSet and ensure the candidates we are most likely interested in are first.


Affects: 3.2.12, 4.0.8, 4.1.2

Attachments:

Issue Links:

Backported to: 4.0.9, 3.2.13

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Andy, let's try to fix this for 4.1.3 still (i.e. by the end of the week)...

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Andy Clement commented

This is a patch that fixes it. I'm a little nervous since this is quite an important area. It does pass the new test as well as all existing tests. It'd be good if someone else cast an eye over it.

@spring-projects-issues
Copy link
Collaborator Author

Andy Clement commented

Juergen - if you let me know what you think of the patch, I can get it in asap.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Andy, this looks fine to me. I'm rolling it in right away in a slightly streamlined fashion (also reducing the multi-transformation of the Method set/array/list - another suboptimal arrangement in the old version of that code).

I'm even wondering whether to backport this to 4.0.9 and 3.2.13 at the end of December since such runtime differences between JVMs can be quite unpleasant and hard to track down :-(

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Andy Clement commented

Thanks for rolling it in. It is a nasty issue when you hit it so could be worth back porting, yes.

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) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants