Repository navigation
Conversation
Prior to this commit, compiling a SpEL Elvis expression whose operands have the same primitive type, such as `count ?: 0` for an int property or `3.5d ?: 4.5d`, failed with a VerifyError, reported as "Failed to instantiate CompiledExpression". In IMMEDIATE compiler mode, every evaluation after the first one therefore failed, whereas MIXED mode fell back to interpreted mode. The generated code boxed the left-hand value for the null check but did not box the right-hand value, since the exit type descriptor was primitive, so the two branches left different types on the stack. Since a primitive value is neither null nor an empty String, this commit only generates the code for the left-hand operand in that case, boxing its value if the exit type descriptor is not primitive. 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.
Compiling a SpEL Elvis expression whose operands have the same primitive
type, such as
count ?: 0for anintproperty or3.5d ?: 4.5d,fails with a
VerifyError("Failed to instantiate CompiledExpression").In
IMMEDIATEcompiler mode, every evaluation after the first onethrows, while
MIXEDmode falls back to interpreted mode.Elvis.generateCode()boxes the left-hand value for the null check, butit does not box the right-hand value when the exit type descriptor is
primitive (which is the case when both operands have the same primitive
type), so the two branches leave different types on the stack. Operands
of different types, such as
3 ?: 'foo', are not affected since bothvalues are boxed.
A primitive value is neither
nullnor an emptyString, so in thatcase this change only generates the code for the left-hand operand,
boxing its value if the exit type descriptor is not primitive. The
elsebranch that boxed the left-hand value is no longer needed, and avoidleft-hand operand keeps its current behavior.The new test covers
int,long,doubleandbooleanliterals aswell as a method returning
int; it fails without the change and passeswith it.
./gradlew :spring-expression:checkpasses on JDK 25.7.0.x is affected as well: the left-hand value has been boxed for the
null check since gh-19758, but the right-hand value of an Elvis
expression with a primitive exit type never was.