sahvx655-wq opened a new pull request, #417:
URL: https://github.com/apache/commons-validator/pull/417

   ShortValidator.processParsedValue narrowed the parsed value with `((Number) 
value).longValue()` and then range-checked it, unlike `ByteValidator`, 
`IntegerValidator` and `LongValidator` which first check the value is a `Long`. 
A `NumberFormat` with `parseIntegerOnly` set only stops at the decimal 
separator, so a fractional value written with a negative exponent and no 
decimal point, such as `15E-1` (1.5) or `1E-100`, is still recognised and 
parses in full to a fractional `Double` rather than a `Long`. `longValue()` 
then truncates it towards zero, so `validate("15E-1")` returns `1` and 
`isValid("15E-1")` reports `true`, while the three sibling validators return 
`null` for the same input. Plain decimal fractions like `1.5` are already 
rejected, so the exponent and decimal forms behave inconsistently and a caller 
is handed a silently truncated value it never entered.
   
   The fix guards on `value instanceof Long` before the conversion, so a 
non-`Long` parse result (a fractional `Double`, or one outside the long range) 
now returns `null`, matching the other three integer validators and their 
"Parsed value will be Long if it fits in a long and is not fractional" comment. 
Keeping the check inside `processParsedValue` means every `validate`/`isValid` 
overload inherits the corrected behaviour without callers having to pre-screen 
their input. A `ShortValidatorTest` case covers it and fails on the current 
code (`validate` returns `1`) before passing with the guard in place.
   
   Before you push a pull request, review this list:
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [ ] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use 
Artificial Intelligence (AI).
   - [ ] I used AI to create any part of, or all of, this pull request. Which 
AI tool was used to create this pull request, and to what extent did it 
contribute?
   - [x] Run a successful build using the default 
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command 
line by itself.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied. This may not always be possible, 
but it is a best practice.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body. Note that a maintainer may squash commits during the merge process.
   


-- 
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]

Reply via email to