Skip to content

IllegalArgumentException is thrown on parsing a bad SpEL expr, while ParseException is expected #33291

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

Closed
fishautumn opened this issue Jul 30, 2024 · 1 comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@fishautumn
Copy link

Affects: 5.x.x 6.x.x (not sure about older versions)

I'm using Spring Expression Language (SpEL) to allow user to specify customized data filter criteria.

As user can input any text for the criteria, I need validate the input SpEL expression. I did it with function SpelExpressionParser#parseRaw and consider ParseException as the signal of bad expression.

I found it throws IllegalArgumentException for some bad expression.

repro code:

new SpelExpressionParser().parseRaw("/^REGEX_PREFIX_/.test(myVariable)");

error log:

java.lang.IllegalArgumentException: Operand must not be null

	at org.springframework.util.Assert.notNull(Assert.java:172)
	at org.springframework.expression.spel.ast.SpelNodeImpl.<init>(SpelNodeImpl.java:80)
	at org.springframework.expression.spel.ast.Operator.<init>(Operator.java:58)
	at org.springframework.expression.spel.ast.OperatorPower.<init>(OperatorPower.java:38)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPowerIncDecExpression(InternalSpelExpressionParser.java:322)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatProductExpression(InternalSpelExpressionParser.java:299)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatSumExpression(InternalSpelExpressionParser.java:278)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatRelationalExpression(InternalSpelExpressionParser.java:233)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatLogicalAndExpression(InternalSpelExpressionParser.java:220)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatLogicalOrExpression(InternalSpelExpressionParser.java:207)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatExpression(InternalSpelExpressionParser.java:168)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:138)
	at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:63)
	at org.springframework.expression.spel.standard.SpelExpressionParser.parseRaw(SpelExpressionParser.java:58)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 30, 2024
@snicoll
Copy link
Member

snicoll commented Jul 31, 2024

Thanks for the suggestion but that's not how the SpEL parser works. I agree it would be nice if it would consistently throw a ParseException with a dedicated message that describes what the problem is and where but it would be a significant task. If you look at the spel.ast package, there are a lot of Assert calls like the one you're hitting above.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2024
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 31, 2024
@sbrannen sbrannen changed the title IllegalArgumentException is throwed on parsing a bad SpEL expr, while ParseException is expected IllegalArgumentException is thrown on parsing a bad SpEL expr, while ParseException is expected Aug 8, 2024
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Aug 8, 2024
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: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants