quarkusio/quarkus · error · NullPointerException

Multipart field value cannot be null

Error message

Multipart field value cannot be null

What it means

The simple String-value constructor requires a non-null value and throws NullPointerException when the field value is null. A text part with a null value cannot be encoded into the multipart body, so the library rejects it during construction.

Source

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

        this.name = name;
        this.multiByteContent = content;
        this.mediaType = mediaType;
        this.filename = filename;
        this.text = text;

        this.isObject = false;
        this.value = null;
        this.pathname = null;
        this.type = null;
        this.content = null;
    }

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

    public QuarkusMultipartFormDataPart(String name, String filename, String pathname, String mediaType, boolean text) {
        if (name == null) {
            throw new NullPointerException("Multipart field name cannot be null");
        }
        if (filename == null) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Skip adding the part when the value is null (conditional add)
  2. Pass an empty string if the field must be present but has no value
  3. Coalesce with a default before construction

Example fix

// before
parts.add(new QuarkusMultipartFormDataPart("note", note, null)); // note == null
// after
if (note != null) {
    parts.add(new QuarkusMultipartFormDataPart("note", note, null));
}
Defensive patterns

Strategy: validation

Validate before calling

if (value == null) throw new IllegalArgumentException("Multipart field value must not be null (omit the part or use \"\")");

Try / catch

try {
    return new QuarkusMultipartFormDataPart(name, value, filename);
} catch (NullPointerException e) {
    throw new IllegalArgumentException("Field value is required; skip the part if optional", e);
}

Prevention

When it happens

Trigger: Calling new QuarkusMultipartFormDataPart(name, null, filename) — a null string value, typically when the value is fetched from a map/config lookup that misses, or from a DTO getter returning null.

Common situations: Sending optional fields where the caller passes null instead of omitting the part or an empty string; lookups on maps with absent keys.

Related errors


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