quarkusio/quarkus · error · NullPointerException

Multipart field name content cannot be null when sending fil

Error message

Multipart field name content cannot be null when sending files

What it means

This NullPointerException is thrown by the Buffer-based QuarkusMultipartFormDataPart constructor when the content parameter is null. An in-memory multipart part must have actual bytes to encode; a null Buffer cannot be written into the request body. The constructor fails fast before any network activity.

Source

Thrown at independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/QuarkusMultipartFormDataPart.java:122

        this.filename = filename;
        this.pathname = pathname;
        this.content = null;
        this.multiByteContent = null;
        this.mediaType = mediaType;
        this.text = text;
        this.isObject = false;
        this.type = null;
    }

    public QuarkusMultipartFormDataPart(String name, String filename, Buffer content, String mediaType, boolean text) {
        if (name == null) {
            throw new NullPointerException("Multipart field name cannot be null");
        }
        if (filename == null) {
            throw new NullPointerException("Multipart field name filename cannot be null when sending files");
        }
        if (content == null) {
            throw new NullPointerException("Multipart field name content cannot be null when sending files");
        }
        if (mediaType == null) {
            throw new NullPointerException("Multipart field media type cannot be null");
        }
        this.name = name;
        this.value = null;
        this.filename = filename;
        this.pathname = null;
        this.content = content;
        this.multiByteContent = null;
        this.mediaType = mediaType;
        this.text = text;
        this.isObject = false;
        this.type = null;
    }

    public String name() {
        return name;

View on GitHub (pinned to e1c734241f)

Solutions

  1. Ensure the Buffer is created before the call, e.g. Buffer.buffer(bytes) with a non-null byte[]
  2. Handle the async read completion before building the multipart form
  3. If content may legitimately be absent, skip adding the part rather than passing a null Buffer

Example fix

// before
byte[] bytes = loadBytes(); // may return null
form.binaryFileUpload("file", filename, Buffer.buffer(bytes), mime);
// after
byte[] bytes = loadBytes();
if (bytes != null) {
    form.binaryFileUpload("file", filename, Buffer.buffer(bytes), mime);
}
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(bytes, "content bytes must not be null");
Buffer content = Buffer.buffer(bytes);

Type guard

boolean hasContent(Buffer content) {
    return content != null && content.length() > 0;
}

Prevention

When it happens

Trigger: Calling QuarkusMultipartFormDataPart(name, filename, (Buffer) null, mediaType, text) or MultipartForm.binaryFileUpload(name, filename, (Buffer) null, mediaType) with a null Buffer.

Common situations: Buffer.buffer(...) built from a byte[] that is null; an async load (fileSystem.readFile) whose result was not yet assigned/failed silently; mapping an Optional<byte[]> that was empty to null.

Related errors


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