didi/DoKit · error · IllegalStateException

No body found; has createBodySink been called?

Error message

No body found; has createBodySink been called?

What it means

Thrown by RequestBodyHelper (getDisplayBody / getContentType etc. via throwIfNoBody) when read methods are accessed before createBodySink() has initialized the internal deflated output buffer. The helper is a write-first pipeline: createBodySink() allocates mDeflatedOutput, and only then do the read accessors become legal.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/network/core/RequestBodyHelper.java:54

        } else {
            deflatingOutput = deflatedOutput;
        }
        mDeflatedOutput = deflatedOutput;
        return deflatingOutput;
    }

    public byte[] getDisplayBody() {
        throwIfNoBody();
        return mDeflatedOutput.toByteArray();
    }

    public boolean hasBody() {
        return mDeflatedOutput != null;
    }

    private void throwIfNoBody() {
        if (!hasBody()) {
            throw new IllegalStateException("No body found; has createBodySink been called?");
        }
    }
}

View on GitHub (pinned to 626827cddb)

Solutions

  1. Guard every read with hasBody(): if (helper.hasBody()) byte[] body = helper.getDisplayBody();
  2. Ensure createBodySink() is called on the body path before any accessor, including error paths
  3. Fix control flow that bypasses createBodySink (early returns / exceptions between intercept and read)

Example fix

// before
byte[] body = requestBodyHelper.getDisplayBody(); // throws if no sink created

// after
byte[] body = requestBodyHelper.hasBody() ? requestBodyHelper.getDisplayBody() : null;
Defensive patterns

Strategy: validation

Validate before calling

if (requestBodyHelper.hasBody()) {
    byte[] body = requestBodyHelper.getDisplayBody();
} else {
    // createBodySink() was never called for this request/response
}

Prevention

When it happens

Trigger: Calling getDisplayBody() before createBodySink() was ever invoked — e.g. an interceptor reading the body snapshot for a request/response where the body sink was skipped (GET requests, 304 responses, or an early return path that bypassed createBodySink).

Common situations: Custom interceptors that unconditionally log the display body even when the response has no body; Read paths that run after a createBodySink failure (exception swallowed, leaving hasBody() == false); Ordering bugs where the read happens on a different thread before the write side finished setup

Related errors


AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14). Data as JSON: /api/errors/385aa1bd9a5209d9. Report an issue: GitHub.