Correctly resolve accessors for static properties on Class
Issue: SPR-11609
(cherry picked from commit 3af8a32)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user