Include target types in MethodReference cache

Update the cached MethodExecutor in MethodReference to include the
target type. Prevents the incorrect use of the cache when the
SpEL expression refers to a different target object.

Issue: SPR-10657
This commit is contained in:
Phillip Webb
2013-06-28 13:14:23 +02:00
parent 60532cbd1e
commit bf4563e204
2 changed files with 41 additions and 20 deletions

View File

@@ -45,8 +45,8 @@ public class CachedMethodExecutorTests {
@Test
public void testCachedExecution() throws Exception {
Expression expression = this.parser.parseExpression("echo(#something)");
public void testCachedExecutionForParameters() throws Exception {
Expression expression = this.parser.parseExpression("echo(#var)");
assertMethodExecution(expression, 42, "int: 42");
assertMethodExecution(expression, 42, "int: 42");
@@ -54,18 +54,32 @@ public class CachedMethodExecutorTests {
assertMethodExecution(expression, 42, "int: 42");
}
@Test
public void testCachedExecutionForTarget() throws Exception {
Expression expression = this.parser.parseExpression("#var.echo(42)");
assertMethodExecution(expression, new RootObject(), "int: 42");
assertMethodExecution(expression, new RootObject(), "int: 42");
assertMethodExecution(expression, new BaseObject(), "String: 42");
assertMethodExecution(expression, new RootObject(), "int: 42");
}
private void assertMethodExecution(Expression expression, Object var, String expected) {
this.context.setVariable("something", var);
this.context.setVariable("var", var);
assertEquals(expected, expression.getValue(this.context));
}
public static class RootObject {
public static class BaseObject {
public String echo(String value) {
return "String: " + value;
}
}
public static class RootObject extends BaseObject {
public String echo(int value) {
return "int: " + value;
}