Skip to content

SpEL ternary and Elvis expressions are missing enclosing parentheses in toStringAST() #29463

@MisterRnobe

Description

@MisterRnobe

Affects: 5.2.23


Hi

Today I faced with the following problem: ternary operator loses parenthesis after I call .toStringAST(). I implemented the test reproducing the bug:

        var spelExpressionParser = new SpelExpressionParser();
        var expression = (SpelExpression) spelExpressionParser.parseExpression("(a ? 1 : 0) * 10");

        assertEquals("((a ? 1 : 0) * 10)", expression.getAST().toStringAST());

And it fails with the error

org.opentest4j.AssertionFailedError: expected: <((a ? 1 : 0) * 10)> but was: <(a ? 1 : 0 * 10)>

In fact, the actual expression is different since it multiplies 0 to 10 first and then applies ternary operator

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions