{"record":{"id":"5f5ad9c8a8febae8","repo":"quarkusio/quarkus","slug":"media-type-was-null","errorCode":null,"errorMessage":"Media type was null","messagePattern":"Media type was null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/MediaTypeHeaderDelegate.java","lineNumber":127,"sourceCode":"        } else {\n            return new MediaType(major, subtype);\n        }\n    }\n\n    public static boolean quoted(String str) {\n        for (int i = 0; i < str.length(); i++) {\n            char c = str.charAt(i);\n            for (char q : quotedChars) {\n                if (c == q)\n                    return true;\n            }\n        }\n        return false;\n    }\n\n    public MediaType fromString(String type) throws IllegalArgumentException {\n        if (type == null)\n            throw new IllegalArgumentException(\"Media type was null\");\n        return parse(type);\n    }\n\n    public String toString(MediaType o) {\n        if (o == null)\n            throw new IllegalArgumentException(\"Param was null\");\n        MediaType type = o;\n        String result = reverseMap.get(type);\n        if (result == null) {\n            result = internalToString(type);\n            final int size = reverseMap.size();\n            if (size >= MAX_MT_CACHE_SIZE) {\n                reverseMap.clear();\n                map.clear();\n            }\n            reverseMap.put(type, result);\n            map.put(result, type);\n        }","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/MediaTypeHeaderDelegate.java#L109-L145","documentation":"MediaTypeHeaderDelegate.fromString requires a non-null string because the JAX-RS HeaderDelegate contract mandates throwing IllegalArgumentException when the input is null. There is no default media type to substitute, so null input is rejected immediately before parsing.","triggerScenarios":"Passing a null String to MediaTypeHeaderDelegate.fromString(null), or indirectly via RuntimeDelegate header conversion when a header value variable is null (e.g. an unset config property or missing request header fed to MediaType conversion).","commonSituations":"Reading a Content-Type/Accept header that is absent and passing it straight to conversion; @ConfigProperty or map lookups returning null; deserializing optional header values into MediaType without a null check.","solutions":["Check the string for null before calling fromString and substitute a sensible default such as MediaType.APPLICATION_JSON or APPLICATION_OCTET_STREAM.","Treat a null header as 'not specified' in your protocol logic instead of converting it.","Catch IllegalArgumentException if null input is expected and handle it as an empty-media-type case."],"exampleFix":"// before\nMediaType mt = MediaType.valueOf(headerValue);\n// after\nMediaType mt = headerValue == null ? MediaType.APPLICATION_OCTET_STREAM : MediaType.valueOf(headerValue);","handlingStrategy":"type-guard","validationCode":"if (headerValue == null || headerValue.isBlank()) {\n    // treat as 'no media type specified'\n}","typeGuard":"static boolean hasMediaType(String s) {\n    return s != null && !s.isBlank();\n}","tryCatchPattern":"try {\n    return MediaTypeHeaderDelegate.INSTANCE.fromString(type);\n} catch (IllegalArgumentException e) {\n    return MediaType.APPLICATION_OCTET_STREAM; // default for null/invalid\n}","preventionTips":["Null-check header values pulled from maps/config before conversion.","Use Optional<String> for optional headers to force explicit handling.","Default to APPLICATION_OCTET_STREAM when no content type is known.","Log the original null source so config/header omissions surface early."],"tags":["http","media-type","null-check","jaxrs"],"backgroundTag":"null-header-value","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}