quarkusio/quarkus · error · NoContentException

No content

Error message

No content

What it means

PrimitiveBodyHandler throws a jakarta.ws.rs.NoContentException with message "No content" when the entity stream is empty (0 bytes) and empty bodies are not allowed. Several primitive/body readers reuse this helper, which refuses to produce a value from an empty entity.

Source

Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/providers/serialisers/PrimitiveBodyHandler.java:29

public abstract class PrimitiveBodyHandler {

    public String readFrom(InputStream entityStream, boolean allowEmpty) throws IOException {
        byte[] bytes;
        if (entityStream instanceof ByteArrayInputStream) {
            bytes = new byte[entityStream.available()];
            entityStream.read(bytes);
        } else {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] buf = new byte[1024]; //TODO: fix, needs a pure vert.x async read model
            int r;
            while ((r = entityStream.read(buf)) > 0) {
                out.write(buf, 0, r);
            }
            bytes = out.toByteArray();
        }
        if (!allowEmpty) {
            if (bytes.length == 0) {
                throw new NoContentException("No content");
            }
        }
        return new String(bytes, StandardCharsets.UTF_8);
    }

}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Check the response status/Content-Length before reading an entity and handle 204/empty bodies explicitly
  2. Have the server return a body when clients expect one
  3. Read as Response and inspect the entity presence rather than mapping directly to a primitive

Example fix

// before
String body = client.target(url).request().get(String.class); // throws on empty body
// after
Response resp = client.target(url).request().get();
String body = resp.hasEntity() ? resp.readEntity(String.class) : null;
Defensive patterns

Strategy: try-catch

Validate before calling

Response resp = client.target(url).request().get();
if (resp.getStatus() == 204 || !resp.hasEntity()) { return null; } // skip entity read

Type guard

boolean hasBody(jakarta.ws.rs.core.Response r) { return r != null && r.hasEntity() && r.getLength() != 0; }

Try / catch

try {
    String body = response.readEntity(String.class);
} catch (NoContentException e) {
    // server returned an empty body; treat as absent
    String body = null;
}

Prevention

When it happens

Trigger: Receiving an HTTP response with an empty body (e.g. 204 No Content, or a 200 with zero-length body) while the client expects a primitive/String entity.

Common situations: Server endpoints changed to return 204 or empty bodies; clients calling DELETE-style endpoints expecting a body; misconfigured server returning nothing on error-free paths.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/534d741711799490. Report an issue: GitHub.