quarkusio/quarkus · error · NullPointerException
Multipart field media type cannot be null
Error message
Multipart field media type cannot be null
What it means
The object-valued constructor of QuarkusMultipartFormDataPart requires a non-null mediaType and throws NullPointerException when it is null. The media type is needed to set the part's Content-Type in the multipart body, so a null value would yield an invalid part. Validation happens eagerly in the constructor.
Source
Thrown at independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/QuarkusMultipartFormDataPart.java:38
private final Multi<Byte> multiByteContent;
public QuarkusMultipartFormDataPart(String name, Buffer content, String mediaType, Class<?> type) {
this(name, null, content, mediaType, type);
}
public QuarkusMultipartFormDataPart(String name, String filename, Buffer content, String mediaType, Class<?> type) {
this.name = name;
this.filename = filename;
this.content = content;
this.mediaType = mediaType;
this.type = type;
this.multiByteContent = null;
if (name == null) {
throw new NullPointerException("Multipart field name cannot be null");
}
if (mediaType == null) {
throw new NullPointerException("Multipart field media type cannot be null");
}
if (type == null) {
throw new NullPointerException("Multipart field media type cannot be null");
}
this.isObject = true;
this.value = null;
this.pathname = null;
this.text = false;
}
public QuarkusMultipartFormDataPart(String name, String filename, Multi<Byte> content, String mediaType, boolean text) {
if (name == null) {
throw new NullPointerException("Multipart field name cannot be null");
}
if (mediaType == null) {
throw new NullPointerException("Multipart field media type cannot be null");
}
View on GitHub (pinned to e1c734241f)
Solutions
- Provide an explicit media type, e.g. "application/json" for POJO parts
- In REST Client interfaces, specify @Part(value="field", contentType = MediaType.APPLICATION_JSON)
- Check the code path that computes the media type and ensure it cannot return null
Example fix
// before
new QuarkusMultipartFormDataPart("data", dto, null, "object");
// after
new QuarkusMultipartFormDataPart("data", dto, MediaType.APPLICATION_JSON, "object"); Defensive patterns
Strategy: validation
Validate before calling
if (mediaType == null || mediaType.isBlank()) throw new IllegalArgumentException("Multipart part media type must not be null"); Try / catch
try {
return new QuarkusMultipartFormDataPart(name, value, mediaType, type);
} catch (NullPointerException e) {
throw new IllegalArgumentException("Provide a mediaType (e.g. application/json) for the part", e);
} Prevention
- Default to MediaType.APPLICATION_JSON for POJO parts
- Set contentType explicitly on @Part annotations
- Never forward possibly-null media types from config without defaults
When it happens
Trigger: Calling new QuarkusMultipartFormDataPart(name, objectValue, null, type) with a null mediaType — e.g. when the media type is inferred from an object whose type cannot be mapped, or a null is passed from a computed value.
Common situations: REST Client multipart where @Part consumes a POJO without a resolvable media type; passing MediaType strings built from config that is missing; helper methods forwarding null media types.
Related errors
- Multipart field name cannot be null
- Multipart field value cannot be null
- PartType annotation is only supported on fields and (setter/
- Primitive types are not supported for multipart response map
- Unsupported field type for multipart response mapping: " + t
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/2fb16b5737be0c06.
Report an issue: GitHub.