From d052b307bb09ba1a40f18246e7f9c4148bdd78bc Mon Sep 17 00:00:00 2001 From: Andreas Steinbart Date: Wed, 14 Oct 2026 05:22:03 +0000 Subject: [PATCH] fix(istream): feed throws the SofabException it declares for visitor rejections (#129) IStream.feed declares `throws SofabException`, but a rejection raised by generated code inside the Visitor -- every schema-bound check (MESSAGE_SPEC 7.1) and every receiver cap (6.2.1) -- left feed still wrapped in the UncheckedIOException carrier that let it cross the Visitor interface. A caller catching what the signature promised never caught it; crucible's Java driver had been unwrapping getCause() itself to cope. feed already unwrapped the cause to latch the terminal verdict, then rethrew the wrapper. It now rethrows the cause, for every code: INVALID_MSG, LIMIT_EXCEEDED (whose wrapped delivery had been documented as API) and a visitor's own ARGUMENT. The repeat of a latched LIMIT_EXCEEDED is a plain SofabException too. An UncheckedIOException whose cause is not a SofabException -- the visitor's own I/O failure -- still passes through as thrown, and inside a callback the carriers (Sofab.invalid / limitExceeded / argument, Seq, PayloadAcc) are unchanged: a Visitor method still cannot throw a checked exception. Source-breaking, recorded as (d) in pom.xml's 0.13.0 block. The tests that asserted the carrier at the feed boundary now assert SofabException, and the "whichever carrier" fallbacks in Decode.verdict, BooleanTolerantTest and HeaderLimitsTest are gone so an escaping carrier fails instead of being silently unwrapped. Closes #129 Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- pom.xml | 13 +++++- .../java/org/sofabuffers/sofab/IStream.java | 43 ++++++++++++------- .../java/org/sofabuffers/sofab/Sofab.java | 6 +++ .../sofab/BooleanTolerantTest.java | 6 +-- .../sofabuffers/sofab/HeaderLimitsTest.java | 12 ++---- .../sofab/InvalidIsTerminalTest.java | 20 +++++---- .../sofab/LimitExceededIsTerminalTest.java | 24 ++++------- .../sofabuffers/sofab/ReceiverCapTest.java | 8 ++-- .../sofabuffers/sofab/SequenceGrowthTest.java | 14 +++--- .../java/org/sofabuffers/sofab/SofabTest.java | 8 ++-- .../sofab/Utf8ChunkOffsetTest.java | 10 ++--- .../org/sofabuffers/sofab/Utf8StrictTest.java | 2 +- .../org/sofabuffers/sofab/common/Decode.java | 8 ++-- 14 files changed, 97 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index ac64a34..e54feb0 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ is an argument, an element type is a type parameter. | `Seq.reset` / `Seq.orEmpty` / `Seq.boolsToLongs` | re-arm a reused destination in place; absorb a null field on the encode side; the one boxed-to-primitive conversion `bool` still needs | | `PayloadAcc` | reassemble a `string` / `blob` payload split across feeds — a payload that arrives whole never touches its buffer, and the value never depends on where the split fell; the receiver cap on the announced length arrives as a `Bound` and is compared before the first chunk is taken (§6.2.1) | | `Utf8.decode` | validate a byte range and materialize it, in that order — the only order in which invalid UTF-8 can still be rejected (§6.4) | -| `Sofab.invalid` | the carrier a `Visitor` rejects malformed input through, since a callback declares no checked exception; `IStream.feed` latches it as terminal like its own rejections | +| `Sofab.invalid` | the carrier a `Visitor` rejects malformed input through, since a callback declares no checked exception; `IStream.feed` latches it as terminal like its own rejections and unwraps it, so the caller catches the checked `SofabException` | | `Sofab.limitExceeded` / `Sofab.argument` | the twin carrier for a receiver-limit refusal, which is latched as terminal too but under its own code, **never** as `INVALID`; and the carrier for a defect in the call, such as a bound the caller never stated | | `Bound.schema` / `Bound.receiver` / `Bound.SCHEMA_BOUNDED` | which of §6.2.1's two rules bounds one field, with its number and its verdict: the schema's own `count`/`maxlen` (`INVALID_MSG`), or the deployment's configured cap (`LIMIT_EXCEEDED`); `SCHEMA_BOUNDED` is the numberless statement for a payload whose `maxlen` the caller has already enforced | | `OStream.overScratch` / `copyOfBytesUsed` | a per-thread buffer for a one-shot `encode()`, so the worst case is allocated once per thread rather than once per call. The **size** stays with the caller (CORELIB_PLAN §5.1): generated code passes its own `MAX_SIZE` | diff --git a/pom.xml b/pom.xml index dd663b0..b0b5728 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ is what Maven admits) plus artifactId corelib. The normative half is the namespace, and every symbol is under org.sofabuffers.sofab. --> corelib -