{"record":{"id":"265b30064a2c24fe","repo":"quarkusio/quarkus","slug":"failed-to-parse-media-type","errorCode":null,"errorMessage":"Failed to parse media type ","messagePattern":"Failed to parse media type ","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":77,"sourceCode":"            map.put(type, result);\n            reverseMap.put(result, internalToString(result));\n        }\n        return result;\n    }\n\n    private static MediaType internalParse(String type) {\n        int typeIndex = type.indexOf('/');\n        int paramIndex = type.indexOf(';');\n        String major = null;\n        String subtype = null;\n        if (typeIndex < 0) // possible \"*\"\n        {\n            major = type;\n            if (paramIndex > -1) {\n                major = major.substring(0, paramIndex);\n            }\n            if (!MediaType.MEDIA_TYPE_WILDCARD.equals(major)) {\n                throw new IllegalArgumentException(\"Failed to parse media type \" + type);\n            }\n            subtype = MediaType.MEDIA_TYPE_WILDCARD;\n        } else {\n            major = type.substring(0, typeIndex);\n            if (paramIndex > -1) {\n                if (typeIndex + 1 > paramIndex) {\n                    throw new IllegalArgumentException(\"Failed to parse media type \" + type);\n                }\n                subtype = type.substring(typeIndex + 1, paramIndex);\n            } else {\n                subtype = type.substring(typeIndex + 1);\n            }\n        }\n        if (major.length() < 1 || subtype.length() < 1) {\n            throw new IllegalArgumentException(\"Failed to parse media type \" + type);\n        }\n        if (!isValid(major) || !isValid(subtype)) {\n            throw new IllegalArgumentException(\"Failed to parse media type \" + type);","sourceCodeStart":59,"sourceCodeEnd":95,"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#L59-L95","documentation":"MediaTypeHeaderDelegate.internalParse splits a media type string on '/' and parameters. When no '/' is present (typeIndex == -1), the whole string is treated as the major type, which is only legal if it is the wildcard '*'. Any other bare token (e.g. \"json\", \"text\") throws IllegalArgumentException(\"Failed to parse media type \" + type).","triggerScenarios":"Parsing a media type string with no slash that is not exactly \"*\": MediaType.valueOf(\"json\"), @Produces(\"plain/text\"-style typos like \"text\" alone), or a Content-Type header value of just \"application\".","commonSituations":"Typo'd @Produces/@Consumes annotations missing the '/'; config values (quarkus.* content types) set to bare tokens; clients sending malformed Content-Type/Accept headers; string constants built by concatenation that dropped the subtype.","solutions":["Change the media type to full type/subtype form: \"json\" → \"application/json\", \"*\" → \"*/*\" (the sole legal slash-less form).","Check the raw header/annotation value contains '/' and a non-empty subtype before passing to MediaType.valueOf.","Use MediaType constants (MediaType.APPLICATION_JSON, MediaType.WILDCARD_TYPE) instead of hand-written strings.","Catch IllegalArgumentException around MediaType.valueOf and return HTTP 415/400 appropriately for client-supplied headers."],"exampleFix":"// before\n@Produces(\"json\") // throws when parsed\n// after\n@Produces(\"application/json\")","handlingStrategy":"validation","validationCode":"Pattern MEDIA_TYPE = Pattern.compile(\"^[^/]+/[^;]+(;.*)?$\");\nboolean isParsableMediaType(String type) {\n    return type != null && (\"*\".equals(type.trim()) || MEDIA_TYPE.matcher(type.trim()).matches());\n}","typeGuard":null,"tryCatchPattern":"try {\n    MediaType mt = MediaType.valueOf(type);\n} catch (IllegalArgumentException e) {\n    throw new NotAcceptableException(\"Unsupported media type: \" + type);\n}","preventionTips":["Always use full type/subtype form (\"application/json\", not \"json\")","Use MediaType constants instead of hand-written strings","Remember \"*\" alone is the only legal slash-less form","Validate @Produces/@Consumes values in code review"],"tags":["jaxrs","media-type","parsing","http-headers"],"backgroundTag":"invalid-media-type","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"}