Skip to content
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

Improve diagnostics when repeated text size calculation results in overflow in SpEL #31341

Closed
sbrannen opened this issue Sep 29, 2023 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@sbrannen
Copy link
Member

If the resulting size of repeated text in a SpEL expression (using the repeat operator *) would exceed MAX_REPEATED_TEXT_SIZE, we currently throw a SpelEvaluationException with the MAX_REPEATED_TEXT_SIZE_EXCEEDED message.

However, if the calculation of the repeated text size results in integer overflow, our max size check fails to detect that, and String#repeat(int) throws a preemptive OutOfMemoryError from which the application immediately recovers.

To improve diagnostics for users, we should ensure that we consistently throw a SpelEvaluationException with the MAX_REPEATED_TEXT_SIZE_EXCEEDED message when integer overflow occurs.

@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Sep 29, 2023
@sbrannen sbrannen added this to the 6.0.13 milestone Sep 29, 2023
@sbrannen sbrannen self-assigned this Sep 29, 2023
sbrannen added a commit that referenced this issue Sep 29, 2023
Due to the changes in gh-31341, if the repeat count in a SpEL
expression (using the repeat operator '*') is negative, we throw a
SpelEvaluationException with the MAX_REPEATED_TEXT_SIZE_EXCEEDED
message which is incorrect and misleading.

Prior to gh-31341, a negative repeat count resulted in an
IllegalArgumentException being thrown by String#repeat(), which was
acceptable in terms of diagnostics, but that did not make it
immediately clear to the user what the underlying cause was.

In light of the above, this commit improves diagnostics for a negative
repeated text count in SpEL expressions by throwing a
SpelEvaluationException with a new NEGATIVE_REPEATED_TEXT_COUNT error
message.

Closes gh-31342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant