Correctly resolve accessors for static properties on Class

Issue: SPR-11609
(cherry picked from commit 3af8a32)
This commit is contained in:
Juergen Hoeller
2014-03-26 21:46:38 +01:00
parent 88485dc1a7
commit d8180e1e20
2 changed files with 30 additions and 33 deletions

View File

@@ -285,6 +285,11 @@ public class SpelReproTests extends ExpressionTestCase {
static class MapAccessor implements PropertyAccessor {
@Override
public Class<?>[] getSpecificTargetClasses() {
return new Class<?>[] {Map.class};
}
@Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
return (((Map<?, ?>) target).containsKey(name));
@@ -305,11 +310,6 @@ public class SpelReproTests extends ExpressionTestCase {
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
((Map<String, Object>) target).put(name, newValue);
}
@Override
public Class<?>[] getSpecificTargetClasses() {
return new Class[] { Map.class };
}
}
@@ -1828,9 +1828,11 @@ public class SpelReproTests extends ExpressionTestCase {
@Test
public void SPR11609() {
StandardEvaluationContext sec = new StandardEvaluationContext();
sec.addPropertyAccessor(new MapAccessor());
Expression exp = new SpelExpressionParser().parseExpression(
"T(org.springframework.expression.spel.SpelReproTests$MapWithConstant).X");
assertEquals(1, exp.getValue());
assertEquals(1, exp.getValue(sec));
}