Fix double SPeL evaluation of parameter
When a node of an SPeL expression was a call to a bean referenced in a method argument, the expression was resolved twice. The resolved arguments are now specified to MethodValueRef instead of resolving the arguments again in the constructor Issue: SPR-11445
This commit is contained in:
@@ -29,6 +29,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -1825,6 +1826,39 @@ public class SpelReproTests extends AbstractExpressionTests {
|
||||
assertEquals("two", list.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SPR11445_simple() {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext(new Spr11445Class());
|
||||
Expression expr = new SpelExpressionParser().parseRaw("echo(parameter())");
|
||||
assertEquals(1, expr.getValue(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SPR11445_beanReference() {
|
||||
StandardEvaluationContext context = new StandardEvaluationContext();
|
||||
context.setBeanResolver(new Spr11445Class());
|
||||
Expression expr = new SpelExpressionParser().parseRaw("@bean.echo(@bean.parameter())");
|
||||
assertEquals(1, expr.getValue(context));
|
||||
}
|
||||
|
||||
static class Spr11445Class implements BeanResolver {
|
||||
|
||||
private final AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
public int echo(int invocation) {
|
||||
return invocation;
|
||||
}
|
||||
|
||||
public int parameter() {
|
||||
return counter.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolve(EvaluationContext context, String beanName) throws AccessException {
|
||||
return beanName.equals("bean") ? this : null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SPR11494() {
|
||||
Expression exp = new SpelExpressionParser().parseExpression("T(java.util.Arrays).asList('a','b')");
|
||||
|
||||
Reference in New Issue
Block a user