Skip to content

multipleOf: divisor shown as 1E+2 in messages; 2.x throws on a divisor that overflows double #1328

Closed

Description

@stevehu

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:

schema: {"multipleOf": 1e400}
-> SchemaException: java.lang.NumberFormatException

On master the same schema loads and multipleOf is ignored, because of the Double.isFinite check that came with #1241.

Possible fix: add the same Double.isFinite check to getDivisor on 2.x. Reading such numbers exactly is #1293.

Confirmed on master (47d2fe6) and 2.x (f2387c2), with JDK 25 and Java 8.

Activity

  1. PHJ2000 commented on Oct 14, 2026

    @PHJ2000
    Contributor

    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?

  2. stevehu commented on Oct 14, 2026

    @stevehu
    ContributorAuthor

    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.

  3. PHJ2000 commented on Oct 15, 2026

    @PHJ2000
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions