Skip to content

Tidy up: guard Long overflow before asLong() in generated int validators (EmitType.java) #186

Open

Description

@simbo1905

Sub-issue 7 of 26 from the 2026-11-21 bot-review-comment audit. Parent issue: #179 (Bot review comment tidy up).
Audited origin/main HEAD: 2e5cf37. Audit date: 2026-11-21.

== Finding 7 (verbatim from the audit findings file) ==

  1. PR JTD bytecode codegen via ClassFile API + RFC 8927 conformance #139 — Generated int validators lack a Long-range guard before asLong.
    Author: chatgpt-codex-connector[bot], 2026-02-08. Comment: JTD bytecode codegen via ClassFile API + RFC 8927 conformance #139 (comment)
    Source: json-java21-jtd-codegen/src/main/java/json/java21/jtd/codegen/EmitType.java:256. Current: json-java21-jtd-codegen/src/main/java/json/java21/jtd/codegen/EmitType.java:218-263 (emitIntCore).
    Flagged: "When the instance is a large integer (e.g. 1e20), toLong() can throw JsonAssertionException, which aborts validation instead of returning a schema error. The interpreter explicitly rejects values outside Long range first...". Suggested: mirror the interpreter's guard before the asLong call.
    Still applies: emitIntCore does floor() check then calls JsonNumber.asLong() directly; JsonNumberImpl.asLong() throws JsonValueException for out-of-long values (JsonNumberImpl.java:64-66), so generated int8..uint32 validators throw on 1e20 instead of emitting a schema error.
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