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

Throw SpelParseException for unsupported character in SpelExpressionParser #33767

Closed
MikailBag opened this issue Oct 21, 2024 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@MikailBag
Copy link

MikailBag commented Oct 21, 2024

Reproducer: https://gist.github.com/MikailBag/ed3b036da394aae7c57e89267920f522

Actual expression: "#{m[‘c]}"

(Please note that ‘ is not an ASCII quote)

Expected behavior: program prints "OK" (or maybe "Incorrect success", if the expression is actually correct).

Actual behavior:

> Task :Main.main() FAILED
Exception in thread "main" java.lang.IllegalStateException: Unsupported character '‘' (8216) encountered at position 3 in expression.
	at org.springframework.expression.spel.standard.Tokenizer.process(Tokenizer.java:271)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:135)
	at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:63)
	at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:34)
	at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpressions(TemplateAwareExpressionParser.java:125)
	at org.springframework.expression.common.TemplateAwareExpressionParser.parseTemplate(TemplateAwareExpressionParser.java:66)
	at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:52)
	at Main.main(Main.java:10)

Execution failed for task ':Main.main()'.
> Process 'command '/usr/lib/jvm/java-21-openjdk-amd64/bin/java'' finished with non-zero exit value 1

I consider this behavior incorrect, as SpelExpressionParser is documented to throw (checked) ParseException, and not documented to throw any runtime exceptions (except maybe NullPointerException if input is null).

This issue may be related to #31097.

I was able to reproduce the problem with the latest published stable version v6.1.14.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 21, 2024
@bclozel bclozel added the in: core Issues in core modules (aop, beans, core, context, expression) label Oct 21, 2024
@sbrannen sbrannen changed the title Unexpected IllegalStateException thrown by SpelExpressionParser Unexpected IllegalStateException thrown by SpelExpressionParser Oct 22, 2024
@sbrannen sbrannen self-assigned this Oct 22, 2024
@sbrannen sbrannen changed the title Unexpected IllegalStateException thrown by SpelExpressionParser Throw SpelParseException for unsupported character in SpelExpressionParser Oct 22, 2024
@sbrannen
Copy link
Member

Hi @MikailBag,

Congratulations on submitting your first issue for the Spring Framework! 👍

I consider this behavior incorrect, as SpelExpressionParser is documented to throw (checked) ParseException, and not documented to throw any runtime exceptions (except maybe NullPointerException if input is null).

org.springframework.expression.ParseException is actually an unchecked RuntimeException.

However, I agree that throwing a ParseException (or even better a SpelParseException) for an unsupported character would be better than throwing the IllegalStateException, and I've updated the title of this issue to reflect that.

Cheers,

Sam

@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 22, 2024
@sbrannen sbrannen modified the milestones: 6.2.0, 6.1.15 Oct 22, 2024
@sbrannen sbrannen added type: bug A general bug and removed type: enhancement A general enhancement labels Oct 22, 2024
@sbrannen
Copy link
Member

This has been fixed in c98f314 for inclusion in the upcoming Spring Framework 6.1.15 release.

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) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants