Fixed isWritable for badly formed SpEL expressions
Before this change isWritable() could return true
for a badly formed expression. That is because the
decision about whether something is writable was made
based on the node type rather than whether the node
represented something that could actually be resolved
to be a real thing. This change ensures a resolution
check is done and isWritable() should only return
true if a subsequent setValue() will succeed.
Issue: SPR-10610
@ -384,7 +384,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
@@ -384,7 +384,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
@ -75,6 +75,54 @@ public class SetValueTests extends AbstractExpressionTests {
@@ -75,6 +75,54 @@ public class SetValueTests extends AbstractExpressionTests {
assertFalse("Should not be writable!",e.isWritable(lContext));
fail("Should have had an error because wibble does not really exist");
}catch(SpelEvaluationExceptionsee){
// org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 15): Property or field 'wibble' cannot be found on object of type 'org.springframework.expression.spel.testresources.ArrayContainer' - maybe not public?
// at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:225)
// success!
}
// VARIABLE
// the variable does not exist (but that is OK, we should be writable)
e=parser.parseExpression("#madeup1");
assertTrue("Should be writable!",e.isWritable(lContext));