sahvx655-wq opened a new pull request, #423:
URL: https://github.com/apache/commons-validator/pull/423
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]