sahvx655-wq opened a new pull request, #410: URL: https://github.com/apache/commons-validator/pull/410
The Number-typed range overloads on `DoubleValidator` and `FloatValidator` are inherited from `AbstractNumberValidator`, which tests `value.doubleValue()` against `bound.doubleValue()`. While reviewing the exact-comparison work already done on the `BigInteger` and `BigDecimal` validators I noticed the two floating-point validators still take that narrowing path, so a `BigDecimal` or `BigInteger` bound carrying more significant digits than a `double` can hold is rounded onto the value before the test. `minValue(2^53, BigInteger 2^53 + 1)` returns `true` and `maxValue(2^53, 2^53 - 0.5)` returns `true`, both wrong: a value that sits outside the bound is reported as in range, and it then slips through any `isInRange` guard built on these methods. The two overrides keep the bound as a `BigDecimal` and compare the value's `double` against it, so the bound's precision survives; this follows the `compareTo` comparisons already used in `BigIntegerValidator` and `BigDecimalValidator`. A non-finite operand keeps the old `doubleValue()` comparison so the documented infinity and NaN behaviour is unchanged. Placing the check in the callee means `isInRange(Number, Number, Number)` picks it up through virtual dispatch rather than each caller needing its own guard. - [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]
