Repository navigation
[2.x] Preserve exact multipleOf operands - #1291
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused fix correctly addresses precision loss and includes comprehensive regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Preserves exact multipleOf arithmetic for integral and BigDecimal operands while retaining legacy floating-point behavior.
Changes:
- Avoids lossy
doubleconversion for exact numeric nodes. - Adds regression coverage for large integers and extreme decimals.
| File | Description |
|---|---|
MultipleOfValidator.java |
Uses exact decimal operands where possible. |
MultipleOfValidatorTest.java |
Covers precision and range regressions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Handle extreme numeric scales and trailing-zero inputs without normalization overflow or excessive computation. Preserve exact numeric values in default validation readers while retaining public mapper defaults and compact doubles where lossless. Fix related enum, uniqueness, bounds, and count-limit handling. Preserve custom-mapper behavior and protected validator hooks. Add regression coverage and update the Numeric Precision documentation. Forward nextFieldName() to the underlying parser's fast path. Validation: mvn -B verify on JDK 8; 8,561 tests, 15 skipped, 0 failures or errors.
|
Ported the latest review fixes in 59c4691; the detailed response and parsing measurements are on #1290. This version keeps Jackson 2's decimal scales because its DecimalNode equality is already numeric, retains its YAML non-finite-input behavior, and adapts parser APIs and tests for Java 8. The shared fixes include FloatNode bounds, large-exponent loose values, location-aware reading, conversion-hook compatibility, and count limits. Non-integral/non-finite maxItems now uses the other maximum validators' unrestrictive fallback. Java 8 |
|
Applied the four follow-ups from #1290 in 85d9ce6: float-safe conversion for both multipleOf operands, cache clearing on parser advancement, early rejection of NaN/FloatNode infinity bounds, and shared helpers in Added 19 regression cases. Full |
|
Updated in 7579163 with the same narrowed scope as #1290: only
|
|
Applied the review fixes from #1290 to 2.x. This restores the existing behavior for mixed integer/floating-point inputs and updates conversion-hook handling, divisor messages, and test process cleanup. The changes are adapted for Java 8 and Jackson 2. All 99 |
Keep conversion hooks and the existing primitive fallback for subclasses. Only the concrete built-in validator with concrete IntNode/LongNode inputs uses the direct remainder path. Local JDK 8 measurements show the scaled-dividend subclass case increasing from about 7.66 to 7.86 ns/op; ordinary integer paths improve slightly. Keep this optimization separate so it can be reverted independently.
|
Applied the latest review fixes from #1290 in a98dc32. Mixed-number validation now preserves the existing behavior when a dividend hook applies abs, negate, or scaling, and error messages show the divisor used for the check. The redundant conversions and forked-test cleanup/coverage issues are also addressed. The changes preserve Jackson 2's existing NaN/Infinity behavior, including custom divisor hooks, and use Java 8-compatible APIs. I added a direct integer fast path that skips
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 2.x #1291 +/- ##
======================================
Coverage ? 79.14%
Complexity ? 2097
======================================
Files ? 202
Lines ? 7007
Branches ? 1266
======================================
Hits ? 5546
Misses ? 1007
Partials ? 454 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
stevehu
left a comment
There was a problem hiding this comment.
Thanks for sticking with this through all the rounds. The final version does exactly what we agreed: validation uses what the hooks return, the override detection is gone, and the forked-test cleanup checks waitFor.
Verification (each PR merged into the current base)
MultipleOfValidatorTest: 138 onmaster(JDK 17, 25), 136 on2.x(Java 8, 21). The JSON Schema Test Suite (7261) and the extras pass. The full suite passes onmaster/JDK 25 (9002) and2.x/Java 8 (8876).- Revert check: with the base validator, 45 of 138 tests fail on
masterand 41 of 136 on2.x. - 60k random divisor/value pairs across Int/Long/BigInteger/BigDecimal/Double/Float nodes, compared with an exact
BigDecimalremainder check: no wrong verdicts, messages or exceptions on either branch. The base code gave about 170 wrong verdicts and over 4,000 wrong messages on the same inputs. - I checked
isMultipleOfby hand, including the modular-exponentiation path.
What I pushed to both branches
Both PRs conflicted with their base in CHANGELOG.md after #1326/#1327 merged. I merged the current base and kept both entries. I also changed this entry's reference to the issue, (#1286), so it matches on both branches. CI passes on the new heads.
For later, outside this PR
multipleOf: 100still reportsmust be multiple of 1E+2, which you kept on purpose.- On
2.x, a divisor the reader turns into Infinity (such as1e400) still throws when the schema loads. The reader side is #1293.
Fixes #1286. Corresponding master PR: #1290.
Preserve exact integral and BigDecimal operands in multipleOf validation. For example, 9007199254740993 is rejected as a multiple of 2 and accepted as a multiple of 3. The conversion hooks are used for both directly constructed validators and subclasses, and validation checks their returned values without substituting a rounded divisor.
Mixed integer/Double or Float inputs retain the exact integer value instead of rounding it through double. For example, multipleOf: 2.0 now rejects integer 9007199254740993. Integer divisor 9007199254740993 also rejects input 9007199254740993.0, which the default reader has already rounded to 9007199254740992. Double/Float conversion itself still uses BigDecimal.valueOf(doubleValue()). Reader precision remains a separate issue in #1293.
The integer fast path checks whether the returned dividend can be represented exactly as a long. Other values use coefficient/scale arithmetic without constructing exponent-sized powers. The default divisor conversion retains trailing-zero normalization, while error messages preserve the representation returned by custom divisor hooks. Javadoc and the CHANGELOG describe the exact conversion and its effect on integral dividend scale (for example, 2 instead of 2.0). Zero/negative divisor handling, type-loose conversion and this branch's non-finite-number behavior are unchanged.
Tests cover exact values, mixed inputs, conversion overrides, messages and extreme scales. Forked tests check whether forced termination succeeds and retain the timeout failure if the child is still alive.
Validation: mvn -B -ntp clean verify passes on Java 8 and 17 with Jackson 2; 8,841 tests reported, 15 skipped, no failures or errors on each JDK. All 136 MultipleOfValidatorTest cases pass.