quarkusio/quarkus · error · NotSupportedException

The content-type header value did not correspond to a valid

Error message

The content-type header value did not correspond to a valid media type

What it means

Thrown from MediaTypeMapper.contentTypeFromRequest (called by consumes) when one of the request's Content-Type header values cannot be parsed by MediaTypeHelper.valueOf; the IllegalArgumentException is converted to NotSupportedException (HTTP 415). It indicates a syntactically invalid Content-Type header rather than a mere mismatch with @Consumes.

Source

Thrown at independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/MediaTypeMapper.java:115

        }

        if (selectedResource == null) {
            throw new WebApplicationException(Response.status(Response.Status.NOT_ACCEPTABLE).build());
        }
        requestContext.restart(selectedResource);
    }

    private List<MediaType> contentTypeFromRequest(ResteasyReactiveRequestContext requestContext) {
        List<String> contentTypeList = requestContext.getHttpHeaders().getRequestHeader(HttpHeaders.CONTENT_TYPE);
        if (contentTypeList.isEmpty()) {
            return Collections.singletonList(MediaType.WILDCARD_TYPE);
        }
        List<MediaType> result = new ArrayList<>(contentTypeList.size());
        for (String s : contentTypeList) {
            try {
                result.add(MediaTypeHelper.valueOf(s));
            } catch (IllegalArgumentException e) {
                throw new NotSupportedException("The content-type header value did not correspond to a valid media type");
            }
        }
        return result;
    }

    public MediaType selectMediaType(ResteasyReactiveRequestContext requestContext, Holder holder) {
        MediaType selected = null;
        List<String> accepts = requestContext.getHttpHeaders().getRequestHeader(HttpHeaders.ACCEPT);
        if (!accepts.isEmpty()) {
            boolean sawParseableAccept = false;
            for (String accept : accepts) {
                // MediaTypeHelper.parseHeader skips unparseable tokens; an empty result means the header was malformed
                if (!MediaTypeHelper.parseHeader(accept).isEmpty()) {
                    sawParseableAccept = true;
                }
                Map.Entry<MediaType, MediaType> entry = holder.serverMediaType
                        .negotiateProduces(accept, null);
                if (entry.getValue() != null) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Fix the Content-Type header to a well-formed type/subtype value (e.g. application/json).
  2. Remove duplicate Content-Type headers, keeping a single valid one.
  3. Log the raw incoming headers server-side to identify which client or intermediary emits the malformed value.

Example fix

// before
curl -X POST -H 'Content-Type: application/json;' -d '{}' http://localhost:8080/api
// after
curl -X POST -H 'Content-Type: application/json' -d '{}' http://localhost:8080/api
Defensive patterns

Strategy: validation

Validate before calling

try {
    jakarta.ws.rs.core.MediaType.valueOf(contentType);
} catch (IllegalArgumentException e) {
    throw new IllegalStateException("Refusing to send invalid Content-Type: " + contentType);
}

Try / catch

try {
    return client.post(entity);
} catch (NotSupportedException e) {
    log.error("Invalid Content-Type header value sent", e);
    throw e;
}

Prevention

When it happens

Trigger: The request carries Content-Type header value(s); contentTypeFromRequest loops over contentTypeList and MediaTypeHelper.valueOf(s) throws IllegalArgumentException for a value such as 'application' or 'json;' which is caught and rethrown as this NotSupportedException at line 115.

Common situations: Malformed headers from hand-written clients or scripts; duplicate/conflicting Content-Type headers where one is garbage; middleware injecting placeholder or empty content types.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/09e445e98b620900. Report an issue: GitHub.