Compare exact bound in AbstractNumberValidator range checks#416
Conversation
Signed-off-by: Sahana Bogar <sahvx655@gmail.com>
|
Hello @sahvx655-wq |
|
Makes sense. I'd only added the regression to the four integer validators that route straight through the changed non-fraction branch (Byte/Short/Integer/Long), but you're right that every concrete subclass should exercise the inherited overloads. I've now added the same testNumberRangeExactBound to FloatValidatorTest, CurrencyValidatorTest and PercentValidatorTest. Float hits the unchanged fraction branch and Currency/Percent inherit BigDecimalValidator's exact-compare override, so those assert the behaviour stays correct through each concrete class rather than failing on the old tree. Double, BigDecimal and BigInteger already carry equivalent coverage from the earlier range fixes (testDoubleNumberRangeExactBound, testNumberRangeBeyondDoublePrecision, and testNumberRangeOutsideLongRange/testNumberRangeFractionalBound/testNumberRangeNonFiniteBound), so the whole hierarchy is now covered. Full mvn build is green. |
The DoubleValidator range fix in #410 left the same narrowing in the shared parent.
AbstractNumberValidator.minValue(Number, Number)andmaxValue(Number, Number)fall back tovalue.longValue()againstmin.longValue()on the integer branch, andByteValidator,ShortValidator,IntegerValidatorandLongValidatorinherit that branch without overriding it, so a bound that does not fit in a long is mangled before the comparison ever happens.LongValidator.maxValue(Long.MAX_VALUE, 2^63 held as a BigInteger)narrows the bound toLong.MIN_VALUEand reports the in-range value as over the maximum, while a fractional bound such asminValue(5, 5.5)is floored to 5 and wrongly passes. The visible behaviour is a validator quietly comparing against the wrong bound whenever a small integer value meets aBigInteger,BigDecimalor fractional limit, which is easy to miss because no error is raised.The
BigInteger,BigDecimalandDoubleoverloads already compare the operands exactly and keep thedoubleValue()fallback for a non-finite bound, so I put the same treatment on the parent's integer branch rather than repeat an override in all four subclasses. Sitting the fix in the shared base keeps theNaNand infinity handling identical across the hierarchy and avoids a fifth copy of the comparison. Each of the four affected validator tests gets a regression that fails on the old narrowing branch and passes now.Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.