Environment Details Spring Framework Version: 6.0.6 Spring Boot Version: 3.0.4 Java Version: 17
Description According to the Spring documentation, invoking parseExpression on a SpelExpressionParser should only result in a ParseException when provided with an invalid expression. However, in practice, it throws an IllegalStateException with the message "No node".
Steps to Reproduce
- Create a new SpelExpressionParser instance.
- Attempt to parse an invalid expression, e.g., ")".
- Observe the exception thrown.
Test Code
@Test
void parse_invalidExpression_shouldThrowParseException() {
final var expressionParser = new SpelExpressionParser();
final var invalidExpression = ")";
final var thrown = catchThrowable(() -> expressionParser.parseExpression(invalidExpression));
assertThat(thrown).isInstanceOf(ParseException.class);
}
Expected Behavior The test should pass, with ParseException being thrown for the invalid expression.
Actual Behavior The test fails with the following output:
java.lang.AssertionError:
Expecting actual throwable to be an instance of:
org.springframework.expression.ParseException
but was:
java.lang.IllegalStateException: No node
at org.springframework.util.Assert.state(Assert.java:76)
at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:132)
at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:61)
Comment From: jhoeller
This is actually a regression from our nullability efforts in 5.0 where we introduced additional state assertions. We're going to fix this through refining those assertions, letting the original parse exceptions be arrived at again.
Comment From: SowjanyaReddyGade
I am having the same illegalstateexception issue after I upgraded spring to 5.0.8 release from 4.2.9 version. What is the solution ?
Comment From: bclozel
Spring Framework 5.0.x is out of open source support. This was fixed in 5.3.30.
Please upgrade to a supported version.