Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
SpEL: reduce restrictions on compiling mathematical expressions [SPR-12789] #17386
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:
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?
Referenced from: commits b7ef047
Andy Clement commented
Oh, some numbers:
Performance check for SpEL expression: '(T(Integer).valueOf(payload).doubleValue())/18D'
Basically before these changes the expressions were more complex and slow in interpreted mode (but your intention was to activate the compiler). With these changes the expression is simpler and faster both interpreted and compiled.