{"record":{"id":"2fb16b5737be0c06","repo":"quarkusio/quarkus","slug":"multipart-field-media-type-cannot-be-null","errorCode":null,"errorMessage":"Multipart field media type cannot be null","messagePattern":"Multipart field media type cannot be null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/QuarkusMultipartFormDataPart.java","lineNumber":38,"sourceCode":"    private final Multi<Byte> multiByteContent;\n\n    public QuarkusMultipartFormDataPart(String name, Buffer content, String mediaType, Class<?> type) {\n        this(name, null, content, mediaType, type);\n    }\n\n    public QuarkusMultipartFormDataPart(String name, String filename, Buffer content, String mediaType, Class<?> type) {\n        this.name = name;\n        this.filename = filename;\n        this.content = content;\n        this.mediaType = mediaType;\n        this.type = type;\n        this.multiByteContent = null;\n\n        if (name == null) {\n            throw new NullPointerException(\"Multipart field name cannot be null\");\n        }\n        if (mediaType == null) {\n            throw new NullPointerException(\"Multipart field media type cannot be null\");\n        }\n        if (type == null) {\n            throw new NullPointerException(\"Multipart field media type cannot be null\");\n        }\n        this.isObject = true;\n        this.value = null;\n        this.pathname = null;\n        this.text = false;\n    }\n\n    public QuarkusMultipartFormDataPart(String name, String filename, Multi<Byte> content, String mediaType, boolean text) {\n        if (name == null) {\n            throw new NullPointerException(\"Multipart field name cannot be null\");\n        }\n        if (mediaType == null) {\n            throw new NullPointerException(\"Multipart field media type cannot be null\");\n        }\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/QuarkusMultipartFormDataPart.java#L20-L56","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nnew QuarkusMultipartFormDataPart(\"data\", dto, null, \"object\");\n// after\nnew QuarkusMultipartFormDataPart(\"data\", dto, MediaType.APPLICATION_JSON, \"object\");","handlingStrategy":"validation","validationCode":"if (mediaType == null || mediaType.isBlank()) throw new IllegalArgumentException(\"Multipart part media type must not be null\");","typeGuard":null,"tryCatchPattern":"try {\n    return new QuarkusMultipartFormDataPart(name, value, mediaType, type);\n} catch (NullPointerException e) {\n    throw new IllegalArgumentException(\"Provide a mediaType (e.g. application/json) for the part\", e);\n}","preventionTips":["Default to MediaType.APPLICATION_JSON for POJO parts","Set contentType explicitly on @Part annotations","Never forward possibly-null media types from config without defaults"],"tags":["nullpointer","multipart","rest-client","media-type"],"backgroundTag":"null-required-field","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}