{"record":{"id":"573f8931e89d9733","repo":"quarkusio/quarkus","slug":"param-was-null-573f89","errorCode":null,"errorMessage":"Param was null","messagePattern":"Param 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":133,"sourceCode":"        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        }\n        return result;\n    }\n\n    private static String internalToString(MediaType type) {\n        StringBuilder buf = new StringBuilder(type.getType().length() + type.getSubtype().length() + 1);\n","sourceCodeStart":115,"sourceCodeEnd":151,"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#L115-L151","documentation":"MediaTypeHeaderDelegate.toString converts a MediaType object back to its header string form and rejects a null argument per the HeaderDelegate contract. Since serialization of a null header value is undefined, the delegate throws IllegalArgumentException up front rather than emitting 'null'.","triggerScenarios":"Calling MediaTypeHeaderDelegate.toString(null), or letting a null MediaType flow into header serialization (e.g. setting a Response header/Content-Type from a variable that is null).","commonSituations":"Building a Response where Content-Type is computed from a parsed request value that was never set; caching code storing null media types; generic header-writing utilities receiving null objects.","solutions":["Ensure a non-null MediaType is always produced when the response/entity is built, defaulting to APPLICATION_OCTET_STREAM for unknown types.","Add an explicit null check at the call site and skip or default the header instead of serializing null.","Catch IllegalArgumentException at the header-writing boundary as a defensive guard."],"exampleFix":"// before\nbuilder.header(HttpHeaders.CONTENT_TYPE, computedType); // computedType may be null\n// after\nbuilder.header(HttpHeaders.CONTENT_TYPE, computedType != null ? computedType : MediaType.APPLICATION_OCTET_STREAM);","handlingStrategy":"type-guard","validationCode":"Objects.requireNonNull(computedType, \"Content-Type must be resolved before building the response\");","typeGuard":"static boolean isSerializable(MediaType mt) {\n    return mt != null;\n}","tryCatchPattern":"try {\n    String header = delegate.toString(mediaType);\n} catch (IllegalArgumentException e) {\n    // null media type: skip or use default\n}","preventionTips":["Initialize MediaType fields eagerly; never leave them null on response paths.","Resolve a default Content-Type when the request did not provide one.","Assert non-null media types in unit tests for response-building code.","Avoid generic header-writing utilities that accept nullable values."],"tags":["http","media-type","null-check","serialization"],"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-14T05:17:10.506Z"}