Repository navigation
Preserve exact multipleOf operands - #1290
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused implementation addresses the precision defect while retaining existing floating-point behavior and includes comprehensive regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Preserves exact numeric operands during multipleOf validation, preventing precision loss for large integers and extreme decimals.
Changes:
- Uses exact
BigDecimalrepresentations for integral and decimal operands. - Adds regression coverage for large integers,
BigInteger, and extreme decimal values.
| File | Description |
|---|---|
MultipleOfValidator.java |
Preserves exact divisors and dividends. |
MultipleOfValidatorTest.java |
Adds precision regression tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Code review(xhigh · 8 findings) I found 8 issues in PR #1290. The fix works for integer literals, but there are two problems worth raising before merge:
I also flagged an existing slowdown in the same functions that untrusted instance data can trigger: with typeLoose enabled, the string instance "1e5000000" took 3.8 seconds to validate. I ran each of these on the PR branch to get the timings and behavior. I used a temporary worktree and branch, both now removed, and your feat/validation-execution-limits checkout was not touched. |
|
Thanks for the review. Both PRs have been updated (55e08f1 on master, d4a390c on 2.x).
Full |
|
Code review(xhigh · 14 findings) I reviewed PR #1290 again after the updates, and three new problems block merge. Most of the eight items from the last review are fixed, but the new code and the switch to BigDecimal default readers bring in new crashes and a slowdown. The 14 findings are in the review panel; I reproduced the behavior findings on the PR branch and compared them with master. Blocking:
Compatibility costs of the new default readers:
With a user-supplied mapper: a positive divisor like 1e-400 rounds to 0.0 and is now rejected as "multipleOf must be greater than zero". Master ignored it. The rest are an error in type-loose mode that predates this PR, a few cleanups, and missing tests. I removed the temporary worktrees and the pr-1290 branch I created; your checkout wasn't touched. |
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. Validation: mvn -B verify on JDK 17; 8,647 tests, 30 skipped, 0 failures or errors.
|
Thanks for the reproductions and the detailed review. I have addressed the three merge blockers and added regression coverage. Updates are pushed in c84af35 (master, #1290) and 15cda47 (2.x, #1291).
I also addressed underflow with a user-supplied double-based mapper, protected-method overrides, bounds validation for large numbers, count limits outside the int range, and error messages. The README's Numeric Precision section is updated accordingly. Exact numeric handling is needed beyond Full Performance on JDK 17 (10,000-number arrays): ordinary decimals were 7.5% faster and scientific notation 5.7% faster; integer parsing took 4.2% longer (95% CI +0.9% to +7.5%). Decimals with nine fractional digits averaged 4.9% longer (95% CI −0.3% to +10.0%). Component-isolation measurements point to parser wrapping as the source of the integer overhead in the current exact-reading implementation. Details below. Performance measurements and full test resultsThe baseline is master commit The following measurements cover parsing an array of 10,000 numbers on JDK 17, pinned to logical CPU 0 with
Ordinary decimals and scientific notation improved, while integer parsing showed additional cost. For decimals with nine fractional digits, the observed mean increased, with a confidence interval that includes zero. On 2.x,
Please take another look at the updated changes. |
|
Code review(xhigh · 14 findings) I reviewed the PR owner's latest commit, c84af35 ("Fix numeric edge cases and preserve mapper compatibility"), and reported 14 findings. I checked Jackson's behaviour against the 3.1.1 sources and the actual 3.2.3 classes, but ran no tests. The four that matter most:
The rest are lower priority: a few smaller edge cases, a README line that misstates when zero or negative multipleOf values throw, extra parsing cost for long machine-written doubles (the benchmark only covers integers), and some duplicated or dead code. I also suspected the compact-double shortcut might be wrong on JDK 17 (the library's minimum Java version), but I couldn't test that here. The PR's 10,000-case random test reportedly passes on Java 17, so I left it out. |
|
Thanks for the detailed review. Updated in 1ffd27f, with the 2.x port in #1291 (59c4691).
Full local verify passed: Java 17, 8,740 tests reported / 30 skipped; Java 8 on 2.x, 8,654 / 15 skipped. No failures or errors. The new 93 regressions cover the reviewed behavior and compatibility cases. I also measured parsing arrays of 1,000 values before/after this update, using JMH on one pinned CPU, 2 forks, 3×300 ms warmup and 3×300 ms measurement per fork (microseconds per array):
Java 17 allocation for serialized doubles fell from about 590 KB to 139 KB per array. Java 8's allocation profiler returned implausibly small values, so I am not using those allocation numbers. The short-decimal Java 8 timings have overlapping JMH error ranges; this small local run does not establish a general performance guarantee. |
|
Code review(xhigh · 14 findings) ● Code review(xhigh · 4 findings) The new commit (1ffd27f) fixes all 14 findings from my last review, and I've marked each one fixed. The PR's numeric test classes pass locally (NumericReviewRegressionTest, NumericBoundsReviewTest, CountLimitsReviewTest, MultipleOfExponentReviewTest, ExactMapperRegressionTest, MultipleOfValidatorTest); I didn't run the full suite. How the main ones were fixed:
This pass found four new issues:
|
|
Thanks for checking the previous fixes. Addressed all four follow-ups in 79c0536, with the same changes in 85d9ce6 for #1291.
Added 19 regression cases covering both float operands, invalid bound initialization, existing infinity behavior, and parser advancement/cache reads. Full |
|
Code review(xhigh · 9 findings) I reviewed PR #1290 at xhigh and reported 9 findings. The top four I reproduced by running the PR build on JDK 17; the rest come from reading the source. Reproduced bugs:
The other five, found by reading the code:
The probes ran in a scratch worktree of the PR branch; nothing in your checkout changed. The worktree is still registered with your repo's git, so remove it with git worktree remove when you're done. |
|
Thanks for the additional review. The YAML parsing and zero-representation regressions show that changing the default readers has taken this PR well beyond the original integer-precision fix. I should have separated those changes earlier. Would you be open to splitting the work as follows?
Under this split, a decimal-spelled literal such as Does that scope work for you? I have left both branches unchanged pending your feedback. |
|
Thanks, that split works for me. Changing the default readers is where most of the risk came from, and #1286 only needs A few things for the narrowed version:
I'll review again once the narrowed version is pushed. Thanks again for the careful work on this. |
|
Updated both PRs: 7fedb4a on master and 7579163 on 2.x. Each now changes only The default readers and other keywords are restored. Integral operands and values already supplied as BigDecimal stay exact; the arithmetic safeguards and protected conversion hooks remain. Float conversion and loose exponent overflow keep their base behavior. Zero divisors remain ignored; finite negative divisors are still checked for divisibility as before, without a new SchemaException policy. All remaining tests are in |
|
Code review(xhigh · 8 findings) The narrowed PR still introduces a real regression. Because only one side of multipleOf is now exact, it rejects some numbers the base branch correctly accepted. I reported 8 findings: 4 are about correctness and the rest are cleanup and test quality.
I removed the temporary worktree I used for testing, and your repo is as I found it. |
|
Thanks for checking both branches. I reproduced the two mixed-input cases and fixed them so they pass again. I also added regression tests for both directions and preserved the integer-only precision fix. Exact decimal literal handling and reader changes remain in #1293, as agreed. This fix retains the existing rounding behavior for mixed inputs. I also addressed the remaining findings:
On Java 17, mvn -B -ntp clean verify passes: 8,673 tests reported, 30 skipped, no failures or errors. |
|
Code review(xhigh · 9 findings) The latest commit (1ade33c) fixes the regression from our last round. Every mixed integer/Double/Float case now gets the same accept/reject verdict as base, and all-exact cases match a BigDecimal oracle. I reported 9 findings: two correctness, the rest efficiency, cleanup and tests. What I ran: a JDK 17 comparison of 16,638 combinations covering every number node type and type-loose strings, on base (51dab24) and the PR head.
Two correctness findings:
Speed: the PR is still 3–5× faster than base. Two paths are slower than the previous commit (7fedb4a): ┌───────────────┬─────────┬─────────┬─────────┐ The other findings are cleanup and test-harness issues. I created two temporary worktrees for the probes and removed them; your checkout is unchanged. Three stale worktree entries from earlier sessions are still listed; git worktree prune removes them. |
Preserve overridden dividend conversions and report the divisor used for validation. Remove redundant conversion checks and retain coverage and locale settings in forked tests.
Use direct integer remainder for the default validator and concrete IntNode/LongNode inputs. Keep subclass conversion hooks and their existing integer fast path. Add boundary and custom-node regression coverage. Local JDK 17 JMH measurements keep varying int/long inputs near 2 ns/op. A getDividend override returning 6.0 changes from about 6.9 to 7.5 ns/op.
|
Thanks for the review. I fixed mixed-number validation when a The default integer-only fast path now skips I also unified the mixed-input divisor comparison rule and removed the redundant conversions, condition, and helper. Forked tests no longer assert during cleanup, and they read the output log only on failure. They now inherit the JaCoCo agent and locale settings.
In local JDK 17 JMH measurements before and after the optimization commit (80a0abf → 0fe8e80), the ordinary integer paths were similar or faster. One subclass case where |
|
Code review(xhigh · 7 findings) I reviewed the latest update to PR #1290 (80a0abf and 0fe8e80) and the author's comment, and reported 7 findings. The PR's own MultipleOfValidatorTest passes on the PR head (131 tests on JDK 25); I didn't run the full suite. To check the hook findings, I ran a small probe against both the base commit and the PR head. The top three findings come from that probe and are confirmed; the other four come from reading the code. What the comment claims:
I removed the two worktrees I created, and your checkout is unchanged. git worktree list still shows three entries marked prunable from earlier sessions, including a pr-1290 branch under an old scratchpad. git worktree prune removes them. |
|
I reviewed the agreed integer-precision scope alongside the custom-conversion regressions and protected hook contract issues in your latest review. Locally, I tried applying exact integer arithmetic through the built-in validator factory while retaining the existing conversion hooks and behavior for validators created through the public constructor, including subclasses. This avoids using reflection or comparing returned values to infer whether a hook was overridden. The built-in path fixes the large-integer precision cases, and the custom-conversion cases I checked match the base branch. However, directly constructed validators and subclasses, including those that do not override either hook, would not receive the precision improvement. Consequently, the current PR test expecting exact integer handling in a subclass without overrides still fails with this approach. Would you accept this limit on where the precision fix applies in order to preserve the existing extension behavior? |
|
Thanks for trying the factory-only approach and for asking before pushing it. I'd prefer not to limit the fix that way. The built-in factory is I think the real problem is a requirement I asked for on 10-09: keeping base's double-rounded verdicts for mixed integer/Double operands. All the guessing about hooks comes from that requirement (
What this costs: mixed operands above 2^53, such as integer schema Two smaller items from the last round still apply after this:
Once that's pushed, I'll review both PRs again with an oracle comparison like the earlier rounds. |
|
No worries, and thanks for taking another look at the compatibility requirement. That makes the direction much clearer. I removed the mixed-input compatibility fields and hook-override detection from both PRs. Directly constructed validators and subclasses now validate the values returned by I updated the mixed-input tests, Javadoc, CHANGELOG and PR descriptions to reflect the changed behavior. The default divisor normalization and custom divisor message representations are preserved. I also documented that integral dividends can have a different scale, such as The forked tests now check whether forced termination succeeds. Full Replacing the direct integer shortcut with checks on the hook result increased local JMH timings by roughly 0.3–1 ns/op in integer/plain-subclass cases and 4.6–5.8 ns/op in a subclass returning |
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 2.x PR: #1291.
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 17 and 21; 8,983 tests reported, 30 skipped, no failures or errors on each JDK. All 138 MultipleOfValidatorTest cases pass.