Skip to content

MethodResolver results are cached in SpEL expressions, so changing the context at evaluation time has no effect [SPR-9495] #14129

@spring-projects-issues

Description

@spring-projects-issues

Dave Syer opened SPR-9495 and commented

MethodResolver results are cached in SpEL expressions, so changing the context has no effect. It's nice that there is some control over MethodResolver in StandardEvaluationContext, but because the results are cached in the expression itself (deep in MethodReference so no options I can see to override), they only have an effect once. Users are confused because they set a MethodResolver which apparently is ignored when passed into an expression at evaluation time:

Expression expression = parser.parseExpression("...");
StandardEvaluationContext context = new StandardEvaluationContext();
context.addMethodResolver(new SpiffyMethodResolver());
assertTrue(expression.getValue(context, Boolean.class));
context = new StandardEvaluationContext();
context.addMethodResolver(new CrappyMethodResolver());
assertFalse(expression.getValue(context, Boolean.class)); // FAIL! (it's using the result from the old resolver)

Affects: 3.1.1

Issue Links:

Referenced from: commits c5aa0d1, b7ff26a, baa698e, 6de67cc

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions