Skip to content

SpEL: reduce restrictions on compiling mathematical expressions [SPR-12789] #17386

@spring-projects-issues

Description

@spring-projects-issues

Andy Clement opened SPR-12789 and commented

A few people have noticed that we are currently quite strict on what mathematical expressions we will 'compile' in SpEL. For the standard operators (plus, minus, divide, multiply) we require the operands to be exactly the same type. E.g. both ints, both doubles, both floats, etc. Due to this strict rule you sometimes have to write something funky to get the compiler to compile your expression:

(T(java.lang.Double).parseDouble(payload.someBoxedInt.toString()))/60D

Basically perform a conversion yourself to ensure the operands are compatible. This was done deliberately as we didn't have use cases and every bit of extra flexibility needs many more test cases and enhanced byte code generation - some of the expressions you can write naturally in Java cause extra byte code to be generated that you aren't aware of for converting numbers and we'd need to start generating that too (instructions like i2d). The XD/Integration teams have hit this problem a couple of times.

Under this jira I'd try to lift the restriction.

Juergen (or someone) - are there any upcoming deadlines that you would want me to hit (or not hit) with this feature?


Affects: 4.1.5

Referenced from: commits b7ef047

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions