quarkusio/quarkus · error · IllegalArgumentException
Param was null
Error message
Param was null
What it means
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'.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/MediaTypeHeaderDelegate.java:133
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);
}
return result;
}
private static String internalToString(MediaType type) {
StringBuilder buf = new StringBuilder(type.getType().length() + type.getSubtype().length() + 1);
View on GitHub (pinned to e1c734241f)
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.
Example fix
// before builder.header(HttpHeaders.CONTENT_TYPE, computedType); // computedType may be null // after builder.header(HttpHeaders.CONTENT_TYPE, computedType != null ? computedType : MediaType.APPLICATION_OCTET_STREAM);
Defensive patterns
Strategy: type-guard
Validate before calling
Objects.requireNonNull(computedType, "Content-Type must be resolved before building the response");
Type guard
static boolean isSerializable(MediaType mt) {
return mt != null;
} Try / catch
try {
String header = delegate.toString(mediaType);
} catch (IllegalArgumentException e) {
// null media type: skip or use default
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Media type was null
- param was null
- Param was null
- Media type %s greater than 1: %s
- Media type %s value must be a float: %s
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/573f8931e89d9733.
Report an issue: GitHub.