quarkusio/quarkus · warning · IllegalArgumentException
type cannot be null
Error message
type cannot be null
What it means
RuntimeDelegateImpl.createHeaderDelegate requires a non-null Class argument per the JAX-RS RuntimeDelegate contract and throws IllegalArgumentException when type is null. Valid delegates exist for MediaType, Date, CacheControl, Cookie, EntityTag, Link, NewCookie, and URI types; unknown types later throw UnsupportedOperationException.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/RuntimeDelegateImpl.java:100
public <T> RestResponse.ResponseBuilder<T> createRestResponseBuilder() {
return factory.createRestResponse();
}
@Override
public Variant.VariantListBuilder createVariantListBuilder() {
return new VariantListBuilderImpl();
}
@Override
public <T> T createEndpoint(Application application, Class<T> endpointType)
throws IllegalArgumentException, UnsupportedOperationException {
throw new UnsupportedOperationException();
}
@Override
public <T> HeaderDelegate<T> createHeaderDelegate(Class<T> type) throws IllegalArgumentException {
if (type == null) {
throw new IllegalArgumentException("type cannot be null");
}
if (type.equals(MediaType.class)) {
return (HeaderDelegate<T>) MediaTypeHeaderDelegate.INSTANCE;
} else if (Date.class.isAssignableFrom(type)) {
// for Date, we do subtypes too, because ORM will instantiate java.util.Date as subtypes
// and it's extremely likely we get those here, and we still have to generate a valid
// date representation for them, rather than Object.toString which will be wrong
return (HeaderDelegate<T>) DateDelegate.INSTANCE;
} else if (type.equals(CacheControl.class)) {
return (HeaderDelegate<T>) CacheControlDelegate.INSTANCE;
} else if (type.equals(NewCookie.class)) {
return (HeaderDelegate<T>) NewCookieHeaderDelegate.INSTANCE;
} else if (type.equals(Cookie.class)) {
return (HeaderDelegate<T>) CookieHeaderDelegate.INSTANCE;
} else if (type.equals(EntityTag.class)) {
return (HeaderDelegate<T>) EntityTagDelegate.INSTANCE;
} else if (type.equals(Locale.class)) {
return (HeaderDelegate<T>) LocaleDelegate.INSTANCE;View on GitHub (pinned to e1c734241f)
Solutions
- Ensure a concrete non-null Class is passed to createHeaderDelegate
- If the type comes from generics/reflection, resolve the erased type before the call
- Wrap in Objects.requireNonNull(type) early to fail fast with a clearer error
- For unsupported types, register a custom HeaderDelegate or convert the value to String yourself
Example fix
// before
HeaderDelegate<Foo> d = rd.createHeaderDelegate(genericType); // genericType may be null
// after
if (genericType == null) {
genericType = value.getClass();
}
HeaderDelegate<Foo> d = rd.createHeaderDelegate((Class<Foo>) genericType); Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull(type, "header delegate type must not be null");
Type guard
boolean isDelegateSupported(Class<?> type) {
return type != null && (MediaType.class.equals(type) || Date.class.isAssignableFrom(type)
|| CacheControl.class.equals(type) || Cookie.class.equals(type) || EntityTag.class.equals(type)
|| Link.class.equals(type) || NewCookie.class.equals(type) || URI.class.equals(type));
} Try / catch
try {
return rd.createHeaderDelegate(type);
} catch (IllegalArgumentException e) {
return value -> value == null ? null : value.toString();
} Prevention
- Pass concrete classes, never erased generics
- Null-check generic type parameters before use
- Prefer toString()/serialisation for custom header types
- Handle UnsupportedOperationException for unsupported types
When it happens
Trigger: Calling createHeaderDelegate(null) directly, or indirectly through header serialization code that lost the type (reflection/generic erasure producing a null Class).
Common situations: Custom header-param converters resolving a runtime type that is null; framework integrations passing erased generic types; hand-written code building header delegates.
Related errors
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/aa5055ef0385514b.
Report an issue: GitHub.