quarkusio/quarkus · error · IllegalArgumentException
content must not be null
Error message
content must not be null
What it means
IllegalArgumentException from EntityPartBuilderImpl.content: the entity part content InputStream passed by the caller is null. This is a null-guard on the builder API (same pattern as the adjacent newHeaders null check); the input at fault is the content argument.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/EntityPartBuilderImpl.java:97
public EntityPart.Builder headers(MultivaluedMap<String, String> newHeaders) throws IllegalArgumentException {
if (newHeaders == null) {
throw new IllegalArgumentException("newHeaders must not be null");
}
this.headers = new QuarkusMultivaluedHashMap<>();
this.headers.putAll(newHeaders);
return this;
}
@Override
public EntityPart.Builder fileName(String fileName) throws IllegalArgumentException {
this.fileName = fileName;
return this;
}
@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;View on GitHub (pinned to e1c734241f)
Solutions
- Check the stream source before building: handle getResourceAsStream returning null with a clear error.
- Use Objects.requireNonNull(content) at the call site to fail where the null originates.
- Fix file path/resource name typos so the stream opens successfully.
- If the part may be empty, pass an empty ByteArrayInputStream instead of null.
Example fix
// before
InputStream in = getClass().getResourceAsStream(path);
builder.content(in); // null if resource missing
// after
InputStream in = getClass().getResourceAsStream(path);
if (in == null) {
throw new IllegalStateException("Resource not found: " + path);
}
builder.content(in); Defensive patterns
Strategy: validation
Validate before calling
InputStream in = getClass().getResourceAsStream(path); Objects.requireNonNull(in, "Resource not found: " + path); builder.content(in);
Type guard
InputStream requireStream(InputStream in, String what) {
if (in == null) throw new IllegalStateException("Missing stream for " + what);
return in;
} Try / catch
try {
builder.content(stream);
} catch (IllegalArgumentException e) {
throw new IllegalStateException("Part content stream was null", e);
} Prevention
- Check getResourceAsStream results immediately at the lookup site.
- Use ByteArrayInputStream.empty()/new byte[0] for intentionally empty parts.
- Verify resource paths/classloader visibility in packaged artifacts.
When it happens
Trigger: Calling partBuilder.content((InputStream) null), e.g. when a file/resource stream failed to open (getResourceAsStream returned null) and was passed through.
Common situations: ClassLoader.getResourceAsStream(...) returning null for a missing resource; a file upload input stream that was never initialized; null returned by a stream factory.
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/c2ca63e1ac1ad646.
Report an issue: GitHub.