-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Document limitation of SpEL regarding minimum values for numeric literals #20779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
SpelExpressionParser
fails to parse Integer.MIN_VALUE
SpelExpressionParser
fails to parse Integer.MIN_VALUE
SpelExpressionParser
fails to parse Integer.MIN_VALUE
as literal integer
First and foremost, thank you for the detailed report and apologies for taking so long to process this issue. Please note that, depending on your exact use case, you may be able to work around this limitation if you're using the @Test
void parsingIntegerMinValueFromStringLiteral() {
EvaluationContext context = new StandardEvaluationContext();
ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("T(Integer).valueOf('-2147483648')");
assertThat(expression.getValue(context)).isEqualTo(Integer.MIN_VALUE);
} |
An alternative would be to represent the @Test
void parsingIntegerMinValueFromLongLiteral() {
EvaluationContext context = new StandardEvaluationContext();
ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("-2147483648L");
assertThat(expression.getValue(context, Integer.class)).isEqualTo(Integer.MIN_VALUE);
} Note, however, that the same limitation applies to @Test
void parsingLongMinValueFromLongLiteral() {
EvaluationContext context = new StandardEvaluationContext();
ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("-9223372036854775808L");
assertThat(expression.getValue(context, Long.class)).isEqualTo(Long.MIN_VALUE);
} The above test fails with:
|
SpelExpressionParser
fails to parse Integer.MIN_VALUE
as literal integerInteger.MIN_VALUE
or Long.MIN_VALUE
as literal
After further investigation, I have determined that the following expressions can be used as workarounds, depending on your exact use case. Integer.MIN_VALUE (-2147483648)
Long.MIN_VALUE (-9223372036854775808)
|
After considerable analysis, I have determined that supporting The reason is that the internals of the SpEL tokenizer, parser, and AST node implementations rely heavily on the fact that literals are always positive values. For example, when you specify an integer literal such as Changing the semantics to actually store In light of that and the aforementioned workarounds, I am repurposing this as a documentation issue to point out this limitation. |
Integer.MIN_VALUE
or Long.MIN_VALUE
as literal
@firefoxpdm, are you perhaps the same |
While working on #32187, I realized that the easiest way to express |
Tamas Szekeres opened SPR-16232 and commented
The
Tokenizer
cuts the integer literal-2147483648
(whose value is equal toInteger.MIN_VALUE
) into aMINUS
token and aLITERAL_INT
. The integer token, in itself, falls outside of the integer range, so from that point of view it is understandable that the parsing later fails, but from a usability one, it should work.Affects: 4.3.11, 4.3.12
The text was updated successfully, but these errors were encountered: