Fixed getCachedExecutor race condition in MethodReference
This commit includes a full backport of the changes in SPR-10657, instead of just the initial commit which the original backport request referred to. Issue: SPR-10884 Issue: SPR-10657
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.expression.spel;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.ast.MethodReference;
|
||||
@@ -45,31 +46,42 @@ 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");
|
||||
assertMethodExecution(expression, "Deep Thought", "String: Deep Thought");
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user