You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
multipleOf: divisor shown as 1E+2 in messages; 2.x throws on a divisor that overflows double #1328
Two multipleOf problems found while reviewing #1290 / #1291. Both were there before those PRs, and #1290/#1291 kept them on purpose.
1. Divisor shown in scientific notation in the error message (master and 2.x)
The default getDivisor normalizes the divisor with stripTrailingZeros(), and the message uses BigDecimal.toString(). So a whole-number divisor with trailing zeros is shown in scientific notation:
schema: {"multipleOf": 100}
instance: 350
message: must be multiple of 1E+2
Same for 1000 (1E+3), 2.50E+3 (2.5E+3), and so on.
Possible fix: format the default message with toPlainString(), or with the schema's own number text. Keep toString() (or the custom representation) for values returned by an overridden getDivisor, as #1290 does today. For extreme scales such as 1e-20000000, toPlainString() would build a very long string, so fall back to toString() beyond some size.
2. 2.x only: a divisor that overflows double throws when the schema loads
On 2.x, getDivisor checks divisor != 0 but not Double.isFinite(divisor). With the default reader, which doesn't use USE_BIG_DECIMAL_FOR_FLOATS, 1e400 becomes Infinity, and loading the schema throws:
I'd like to clarify one case in the requirement to preserve the representation returned by a custom getDivisor().
A subclass can inherit getDivisor() unchanged, or override it with just return super.getDivisor(node). Both use the value produced by the default implementation without changing it, so applying the same message formatting to both seems natural to me.
Would displaying 100 instead of 1E+2 in both cases match your intent, or should the second case retain its existing representation?
Good question. The validator can't tell those two apart, and it doesn't need to. Please show 100 in both cases.
You can drop the default/override distinction entirely: format whatever getDivisor returns with one rule, toPlainString() when the plain form is short and toString() otherwise. toPlainString() keeps trailing zeros for non-negative scales, so 3.0 and 100.00 from an override still show as written. That's what overriddenDivisorRetainsMessageRepresentation protects. Only values like 1E+2 or 1E-7 change, which is the same cosmetic issue. My wording in the issue was broader than it needed to be.
Two details:
Compute the plain length from precision() and scale() using long before calling toPlainString(). divisorMessageAtMinimumScale uses scale Integer.MIN_VALUE, where -scale overflows int.
exactDivisorMessage and exactDecimalDivisorMessage assert 1E+2 today. Please update them and pin both sides of the cap; 1e400 is 401 characters in plain form.
Please also add a CHANGELOG entry citing #1328, since the message text changes.
Thanks for clarifying. I’ve applied the formatting rule and added the boundary tests and changelog entries in #1329 (master) and #1330 (2.x). The 2.x PR also includes the non-finite divisor fix.
Activity
PHJ2000 commentedon Oct 14, 2026
I'd like to clarify one case in the requirement to preserve the representation returned by a custom
getDivisor().A subclass can inherit
getDivisor()unchanged, or override it with justreturn super.getDivisor(node). Both use the value produced by the default implementation without changing it, so applying the same message formatting to both seems natural to me.Would displaying
100instead of1E+2in both cases match your intent, or should the second case retain its existing representation?stevehu commentedon Oct 14, 2026
Good question. The validator can't tell those two apart, and it doesn't need to. Please show
100in both cases.You can drop the default/override distinction entirely: format whatever
getDivisorreturns with one rule,toPlainString()when the plain form is short andtoString()otherwise.toPlainString()keeps trailing zeros for non-negative scales, so3.0and100.00from an override still show as written. That's whatoverriddenDivisorRetainsMessageRepresentationprotects. Only values like1E+2or1E-7change, which is the same cosmetic issue. My wording in the issue was broader than it needed to be.Two details:
precision()andscale()usinglongbefore callingtoPlainString().divisorMessageAtMinimumScaleuses scaleInteger.MIN_VALUE, where-scaleoverflowsint.exactDivisorMessageandexactDecimalDivisorMessageassert1E+2today. Please update them and pin both sides of the cap;1e400is 401 characters in plain form.Please also add a CHANGELOG entry citing #1328, since the message text changes.
PHJ2000 commentedon Oct 15, 2026
Thanks for clarifying. I’ve applied the formatting rule and added the boundary tests and changelog entries in #1329 (master) and #1330 (2.x). The 2.x PR also includes the non-finite divisor fix.