Reject out-of-range long and float values in NumberConverter (1.X)#405
Merged
garydgregory merged 1 commit intoJun 26, 2026
Merged
Conversation
The Long branch had no bounds check and the Float branch checked only the upper bound, so out-of-range input was silently clamped to Long.MAX_VALUE or to -Infinity instead of throwing. Add the missing checks mirroring the byte/short/int branches. Ports the master fix (apache#404) to 1.X.
7 tasks
Member
|
TY @rootvector2 , merged 🚀 |
garydgregory
added a commit
that referenced
this pull request
Jun 26, 2026
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.
Port of #404 to the 1.X branch. @garydgregory asked to verify whether the fix applies there, and it does, identically.
NumberConverter.toNumber(Class, Number)range-checks thebyte/short/intbranches, but theLongbranch has no bounds check and theFloatbranch only checks the upper bound, so an out-of-range value is silently clamped instead of rejected: aDouble/BigInteger/BigDecimalbeyondlongrange is truncated/clamped toLong.MAX_VALUE, a locale-parsed String pastlongrange comes back fromDecimalFormatas aDoubleand gets clamped the same way, and aNumberbelow-Float.MAX_VALUEbecomes-Infinity. Fix adds the missing bounds checks to theLongbranch and the lower bound to theFloatbranch, mirroring the existing branches, so out-of-range input throwsConversionException.Regression tests added to
LongConverterTest(testInvalidAmount,testLocaleStringOutOfRange) andFloatConverterTest(negative overflow); they fail without the runtime change. Both converter test classes pass. The fullmvnrun is green except forLocaleBeanificationTest.testContextClassloaderIndependence, which already fails on an unmodified 1.X checkout in my environment (it passes in isolation) and is unrelated to this change.mvn; that'smvnon the command line by itself.