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

  1. Check the stream source before building: handle getResourceAsStream returning null with a clear error.
  2. Use Objects.requireNonNull(content) at the call site to fail where the null originates.
  3. Fix file path/resource name typos so the stream opens successfully.
  4. 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

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


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