reject fractional input in GenericTypeValidator integer helpers#423
Open
sahvx655-wq wants to merge 1 commit into
Open
reject fractional input in GenericTypeValidator integer helpers#423sahvx655-wq wants to merge 1 commit into
sahvx655-wq wants to merge 1 commit into
Conversation
garydgregory
requested changes
Jul 15, 2026
garydgregory
left a comment
Member
There was a problem hiding this comment.
Hello @sahvx655-wq
Please split the new test into one method per API tested, formatByte, formatShort, formatInt. TY!
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.
Following the formatLong range-check fix, formatByte, formatInt and formatShort (the String, Locale overloads) still range-check the parsed number with num.doubleValue() and then narrow it with byteValue()/intValue()/shortValue(). The integer-only NumberFormat only stops parsing at the decimal separator, so a fractional value written with a negative exponent and no decimal point is consumed whole and handed back as a Double: under Locale.US "15E-1" (1.5) satisfies the double bounds and byteValue() floors it, so formatByte returns 1 and formatInt("5E-1") returns 0 instead of null. That earlier fix observed the sibling bounds are exact as doubles, which rules out the long magnitude gap but not this fractional one, so the three helpers report an integer the caller never entered.
Guard each of the three on num instanceof Long before the per-type range check, which NumberFormat returns only for a non-fractional value in long range, matching formatLong and routines.Byte/Short/IntegerValidator. Keeping the decision inside the conversion helper means a value that was never integral comes back as null rather than a silently truncated one. Added GenericTypeValidatorTest#testIntegerLocaleFractional, which fails on the current code and passes with the change.