Compare Exact value in BigDecimalValidator min/max range checks#401
Merged
garydgregory merged 2 commits intoJun 19, 2026
Conversation
Member
|
@sahvx655-wq
|
Contributor
Author
|
Added The new test asserts each of those cases. Full suite stays green (1068 tests) and the default |
Member
|
Merged 🚀 Thank you @sahvx655-wq |
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.
Range checks on BigDecimalValidator narrow the value to a double before comparing
minValue,maxValueandisInRangeran the suppliedBigDecimalthroughdoubleValue()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 theBigIntegerValidatorwork I checked the same range checks here:maxValue(2^53 + 1, 2^53)returnstrue, because2^53 + 1has no exact double and rounds back to2^53, andminValuemisfires 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
BigDecimalwithcompareTo(BigDecimal.valueOf(bound))for finite bounds, the same wayBigIntegerValidatoralready compares.BigDecimal.valueOfrejects NaN and infinity, so non-finite bounds keep thedoubleValue()path and the±Infinitybehaviour covered bytestBigDecimalBeyondDoubleRangeis unchanged.isInRangedelegates to the two methods so the rule lives in one place. The added test fails on the current code and passes with the patch.mvn; that'smvnon the command line by itself.