Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpelExpressionParser throws IllegalStateException instead of ParseException for invalid expression #31097

Closed
andre-aktivconsultancy opened this issue Aug 23, 2023 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Milestone

Comments

@andre-aktivconsultancy
Copy link

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)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 23, 2023
@jhoeller jhoeller added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 23, 2023
@jhoeller jhoeller added this to the 6.0.12 milestone Aug 23, 2023
@jhoeller jhoeller self-assigned this Aug 23, 2023
@jhoeller jhoeller added type: regression A bug that is also a regression and removed type: bug A general bug labels Aug 23, 2023
@jhoeller
Copy link
Contributor

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.

@jhoeller jhoeller added the for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x label Aug 23, 2023
@jhoeller jhoeller changed the title SpelExpressionParser Throws IllegalStateException Instead of ParseException for Invalid Expression SpelExpressionParser throws IllegalStateException instead of ParseException for invalid expression Aug 23, 2023
@github-actions github-actions bot added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.3.x Marks an issue as a candidate for backport to 5.3.x labels Aug 23, 2023
@SowjanyaReddyGade
Copy link

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 ?

@bclozel
Copy link
Member

bclozel commented Feb 3, 2024

Spring Framework 5.0.x is out of open source support. This was fixed in 5.3.30.

Please upgrade to a supported version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

5 participants