{"record":{"id":"e4e17fba8338d190","repo":"quarkusio/quarkus","slug":"malformed-media-type","errorCode":null,"errorMessage":"Malformed media type: ","messagePattern":"Malformed media type: ","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/request/AcceptHeaders.java","lineNumber":136,"sourceCode":"    /**\n     * Gets the media types from a comma-separated list.\n     *\n     * @param header the header value.\n     * @return the listed items in order of appearance or {@code null} if the header didn't contain any entries.\n     */\n    public static Map<MediaType, QualityValue> getMediaTypeQualityValues(String header) {\n        if (header == null)\n            return null;\n        header = header.trim();\n        if (header.length() == 0)\n            return null;\n        Map<MediaType, QualityValue> result = new LinkedHashMap<MediaType, QualityValue>();\n\n        int offset = 0;\n        while (offset >= 0) {\n            int slashIndex = header.indexOf('/', offset);\n            if (slashIndex < 0)\n                throw new BadRequestException(\"Malformed media type: \" + header);\n            String type = header.substring(offset, slashIndex);\n            String subtype;\n            Map<String, String> parameters = null;\n            QualityValue qualityValue = QualityValue.DEFAULT;\n\n            offset = slashIndex + 1;\n            int parameterStartIndex = header.indexOf(';', offset);\n            int itemEndIndex = header.indexOf(',', offset);\n            if (parameterStartIndex == itemEndIndex) {\n                assert itemEndIndex == -1;\n                subtype = header.substring(offset);\n                offset = -1;\n            } else if (itemEndIndex < 0 || (parameterStartIndex >= 0 && parameterStartIndex < itemEndIndex)) {\n                subtype = header.substring(offset, parameterStartIndex);\n                offset = parameterStartIndex + 1;\n                parameters = new LinkedHashMap<String, String>();\n                offset = parseParameters(parameters, header, offset);\n                qualityValue = evaluateAcceptParameters(parameters);","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/request/AcceptHeaders.java#L118-L154","documentation":"getMediaTypeQualityValues() parses the Accept header expecting each item to be type/subtype. If no '/' is found in the remaining header, the item is not a valid media type and this BadRequestException is thrown.","triggerScenarios":"Accept header containing an item without a slash, e.g. 'Accept: text' or 'Accept: *,*/2' handling offsets that skip past items.","commonSituations":"Hand-crafted curl requests with abbreviated media types; misconfigured API clients sending bare tokens like 'json' instead of 'application/json'; HTML forms or custom user-agents with wrong Accept values.","solutions":["Send a fully qualified media type such as application/json or text/plain in the Accept header","Use */* if any content type is acceptable","Fix the client library/configuration that emits the abbreviated media type"],"exampleFix":"// before\ncurl -H \"Accept: json\" ...\n// after\ncurl -H \"Accept: application/json\" ...","handlingStrategy":"validation","validationCode":"boolean allItemsAreMediaTypes(String accept) {\n    if (accept == null) return false;\n    for (String item : accept.split(\",\")) {\n        String type = item.split(\";\")[0].trim();\n        if (!type.equals(\"*\") && !type.contains(\"/\")) return false;\n    }\n    return true;\n}","typeGuard":"boolean isMediaTypeToken(String s) {\n    return s != null && s.matches(\"[\\*a-zA-Z0-9!#$&^_.+-]+/[\\*a-zA-Z0-9!#$&^_.+-]+.*\");\n}","tryCatchPattern":"try {\n    types = AcceptHeaders.getMediaTypeQualityValues(accept);\n} catch (BadRequestException e) {\n    types = Map.of(MediaType.WILDCARD, QualityValue.HIGHEST);\n}","preventionTips":["Always send full type/subtype media ranges","Use */* rather than a bare '*' or 'json' token","Configure HTTP clients to set Accept explicitly (e.g. application/json)"],"tags":["http","accept-header","media-type"],"backgroundTag":"malformed-http-header","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"}