quarkusio/quarkus · error · IllegalArgumentException

Media type was null

Error message

Media type was null

What it means

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.

Source

Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/MediaTypeHeaderDelegate.java:127

        } else {
            return new MediaType(major, subtype);
        }
    }

    public static boolean quoted(String str) {
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            for (char q : quotedChars) {
                if (c == q)
                    return true;
            }
        }
        return false;
    }

    public MediaType fromString(String type) throws IllegalArgumentException {
        if (type == null)
            throw new IllegalArgumentException("Media type was null");
        return parse(type);
    }

    public String toString(MediaType o) {
        if (o == null)
            throw new IllegalArgumentException("Param was null");
        MediaType type = o;
        String result = reverseMap.get(type);
        if (result == null) {
            result = internalToString(type);
            final int size = reverseMap.size();
            if (size >= MAX_MT_CACHE_SIZE) {
                reverseMap.clear();
                map.clear();
            }
            reverseMap.put(type, result);
            map.put(result, type);
        }

View on GitHub (pinned to e1c734241f)

Solutions

  1. Check the string for null before calling fromString and substitute a sensible default such as MediaType.APPLICATION_JSON or APPLICATION_OCTET_STREAM.
  2. Treat a null header as 'not specified' in your protocol logic instead of converting it.
  3. Catch IllegalArgumentException if null input is expected and handle it as an empty-media-type case.

Example fix

// before
MediaType mt = MediaType.valueOf(headerValue);
// after
MediaType mt = headerValue == null ? MediaType.APPLICATION_OCTET_STREAM : MediaType.valueOf(headerValue);
Defensive patterns

Strategy: type-guard

Validate before calling

if (headerValue == null || headerValue.isBlank()) {
    // treat as 'no media type specified'
}

Type guard

static boolean hasMediaType(String s) {
    return s != null && !s.isBlank();
}

Try / catch

try {
    return MediaTypeHeaderDelegate.INSTANCE.fromString(type);
} catch (IllegalArgumentException e) {
    return MediaType.APPLICATION_OCTET_STREAM; // default for null/invalid
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


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