Repository navigation
Conversation
Prior to this commit, a compiled SpEL expression that compared double or float operands with the > or >= operator evaluated to true if one of the operands was NaN, whereas the same expression evaluated to false in interpreted mode, as it does in Java. For example, `1.0d > T(Double).NaN` was false when interpreted but true once compiled. The generated bytecode always used DCMPG/FCMPG, which push 1 if either operand is NaN, so the subsequent IFLE/IFLT jump to the false branch was never taken for > and >=. This commit uses DCMPL/FCMPL for the > and >= operators, as javac does, so that comparisons with NaN evaluate to false in compiled mode as well. Signed-off-by: Jialin Chen <cccll2019@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A compiled SpEL expression that compares
doubleorfloatoperandswith
>or>=evaluates totruewhen one of the operands isNaN.In interpreted mode, as in Java, the result is
false. As a consequence,the same expression changes its result once it gets compiled, for
example after about 100 evaluations in
MIXEDmode.Operator.generateComparisonCode()always emitsDCMPG/FCMPG, whichpush
1if either operand isNaN, so theIFLE/IFLTjump used for>/>=is never taken. javac usesDCMPL/FCMPLfor>and>=,and
DCMPG/FCMPGfor<and<=. This change does the same.<and<=already returnedfalseand keep usingDCMPG/FCMPG.The new parameterized test covers the four operators with
NaNoneither side, for
doubleandfloat. Without the change, the eight>and
>=cases fail once compiled; with the change, all 16 cases pass../gradlew :spring-expression:checkpasses on JDK 25.The generated code has been like this since the SpEL compiler was
introduced, so 7.0.x is affected as well.