SPR-6866: unhelpful NPE when expression badly formed
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3064 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
eeb15e4809
commit
43ea572fd5
|
|
@ -336,7 +336,12 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
|||
if (maybeEatMethodOrProperty(nullSafeNavigation) || maybeEatFunctionOrVar() || maybeEatProjection(nullSafeNavigation) || maybeEatSelection(nullSafeNavigation)) {
|
||||
return pop();
|
||||
}
|
||||
raiseInternalException(t.startpos,SpelMessage.UNEXPECTED_DATA_AFTER_DOT,toString(peekToken()));
|
||||
if (peekToken()==null) {
|
||||
// unexpectedly ran out of data
|
||||
raiseInternalException(t.startpos,SpelMessage.OOD);
|
||||
} else {
|
||||
raiseInternalException(t.startpos,SpelMessage.UNEXPECTED_DATA_AFTER_DOT,toString(peekToken()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
|
|
@ -222,6 +222,20 @@ public class EvaluationTests extends ExpressionTestCase {
|
|||
"org.springframework.expression.spel.testresources.Inventor");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRogueTrailingDotCausesNPE_SPR6866() {
|
||||
try {
|
||||
new SpelExpressionParser().parseExpression("placeOfBirth.foo.");
|
||||
Assert.fail("Should have failed to parse");
|
||||
} catch (ParseException e) {
|
||||
Assert.assertTrue(e instanceof SpelParseException);
|
||||
SpelParseException spe = (SpelParseException)e;
|
||||
Assert.assertEquals(SpelMessage.OOD,spe.getMessageCode());
|
||||
Assert.assertEquals(16,spe.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// nested properties
|
||||
@Test
|
||||
public void testPropertiesNested01() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue