quarkusio/quarkus · error · IllegalArgumentException
type must not be null
Error message
type must not be null
What it means
EntityPart.Builder.content(T, Class<? extends T>) requires an explicit Class used to select the matching MessageBodyWriter; the type argument must not be null or IllegalArgumentException is thrown. The content object itself is validated first.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/EntityPartBuilderImpl.java:111
@Override
public EntityPart.Builder content(InputStream content) throws IllegalArgumentException {
if (content == null) {
throw new IllegalArgumentException("content must not be null");
}
this.content = content;
this.contentType = null;
this.contentGenericType = null;
return this;
}
@Override
public <T> EntityPart.Builder content(T content, Class<? extends T> type) throws IllegalArgumentException {
if (content == null) {
throw new IllegalArgumentException("content must not be null");
}
if (type == null) {
throw new IllegalArgumentException("type must not be null");
}
this.content = content;
this.contentType = type;
this.contentGenericType = type;
return this;
}
@Override
public <T> EntityPart.Builder content(T content, GenericType<T> type) throws IllegalArgumentException {
if (content == null) {
throw new IllegalArgumentException("content must not be null");
}
if (type == null) {
throw new IllegalArgumentException("type must not be null");
}
this.content = content;
this.contentType = type.getRawType();
this.contentGenericType = type.getType();View on GitHub (pinned to e1c734241f)
Solutions
- Pass the concrete class explicitly, e.g. content(dto, MyDto.class).
- Derive the class safely from the entity: entity.getClass() (valid since entity must be non-null anyway).
- In generic helpers, capture the Class as a method parameter and validate it.
- Fix the caller that passes a null Class variable.
Example fix
// before builder.content(entity, typeClass); // typeClass may be null // after builder.content(entity, entity.getClass());
Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull(type, "content type must not be null"); builder.content(entity, type);
Type guard
<T> Class<? extends T> typeOf(T entity) {
@SuppressWarnings("unchecked")
Class<? extends T> c = (Class<? extends T>) entity.getClass();
return c;
} Try / catch
try {
builder.content(entity, type);
} catch (IllegalArgumentException e) {
builder.content(entity, entity.getClass());
} Prevention
- Always pass an explicit class literal (MyDto.class) to content(T, Class).
- In generic helpers, take the Class as a parameter rather than inferring it.
- Use entity.getClass() when no explicit type is available.
When it happens
Trigger: Calling partBuilder.content(entity, null) — passing the entity without a concrete Class, e.g. when the type is derived from a nullable variable or generics erasure.
Common situations: Generic helper methods that capture the type from a parameter which is null; using getClass() on a null entity or forwarding an uninitialized Class variable; reflection-based builders.
Related errors
- name must not be null
- mediaType must not be null
- headerName must not be null
- headerValues must not be null
- newHeaders must not be null
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/3a7cbe67df009696.
Report an issue: GitHub.