sahvx655-wq opened a new pull request, #401: URL: https://github.com/apache/commons-validator/pull/401
**Range checks on BigDecimalValidator narrow the value to a double before comparing** `minValue`, `maxValue` and `isInRange` ran the supplied `BigDecimal` through `doubleValue()` and compared the resulting primitive against the bound. Any value that only differs from the bound past the double mantissa is rounded onto the bound first, so the comparison is settled on a value the caller never passed. Following up on the `BigIntegerValidator` work I checked the same range checks here: `maxValue(2^53 + 1, 2^53)` returns `true`, because `2^53 + 1` has no exact double and rounds back to `2^53`, and `minValue` misfires the same way for a value that rounds up onto its minimum. For a validation routine that is the failure that matters, since it lets an out-of-range value pass a bound check. The comparison now runs against the exact `BigDecimal` with `compareTo(BigDecimal.valueOf(bound))` for finite bounds, the same way `BigIntegerValidator` already compares. `BigDecimal.valueOf` rejects NaN and infinity, so non-finite bounds keep the `doubleValue()` path and the `±Infinity` behaviour covered by `testBigDecimalBeyondDoubleRange` is unchanged. `isInRange` delegates to the two methods so the rule lives in one place. The added test fails on the current code and passes with the patch. - [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]
