quarkusio/quarkus · error · IllegalStateException
No content has been set
Error message
No content has been set
What it means
EntityPart.build() throws IllegalStateException if content(Object) was never called on the builder. An EntityPart without content cannot produce a valid multipart body, so the builder refuses to build. This is a lifecycle misuse of the builder, not a data problem.
Source
Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/EntityPartBuilderImpl.java:175
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer.writeTo(content, rawType, genericType, EMPTY_ANNOTATIONS, mediaType,
new QuarkusMultivaluedHashMap<>(), baos);
return new ByteArrayInputStream(baos.toByteArray());
} catch (IOException e) {
throw new IllegalArgumentException("Failed to serialize content of type " + rawType.getName(), e);
}
} else {
return new ByteArrayInputStream(content.toString().getBytes(StandardCharsets.UTF_8));
}
} else {
return new ByteArrayInputStream(content.toString().getBytes(StandardCharsets.UTF_8));
}
}
@Override
public EntityPart build() throws IllegalStateException, IOException, WebApplicationException {
if (content == null) {
throw new IllegalStateException("No content has been set");
}
InputStream resolvedContent;
if (content instanceof InputStream) {
resolvedContent = (InputStream) content;
} else {
resolvedContent = serialiseContent();
}
MultivaluedMap<String, String> builtHeaders = new QuarkusMultivaluedHashMap<>();
builtHeaders.putAll(headers);
builtHeaders.putSingle("Content-Type", mediaType.toString());
builtHeaders.putSingle("Content-Disposition", EntityPartImpl.buildContentDisposition(name, fileName));
return new EntityPartImpl(name, fileName, builtHeaders, mediaType, resolvedContent, serialisers);
}
}View on GitHub (pinned to e1c734241f)
Solutions
- Call content(...) with a non-null value before build() on every EntityPart.Builder.
- Restructure code so parts are only constructed when their content is available.
- Wrap builder chains in a helper that asserts content was set before build().
Example fix
// before
EntityPart part = EntityPart.withName("meta")
.mediaType(MediaType.APPLICATION_JSON_TYPE)
.build(); // IllegalStateException: No content has been set
// after
EntityPart part = EntityPart.withName("meta")
.content(metadata, new GenericType<Metadata>() {})
.mediaType(MediaType.APPLICATION_JSON_TYPE)
.build(); Defensive patterns
Strategy: validation
Validate before calling
// Builder helper that guarantees content
EntityPart.Builder b = EntityPart.withName("part");
Objects.requireNonNull(content, "content must be set before build()");
b.content(content);
EntityPart part = b.build(); Try / catch
try {
EntityPart part = builder.build();
} catch (IllegalStateException e) {
if ("No content has been set".equals(e.getMessage())) {
throw new ConfigurationException("multipart part built without content; check code path");
}
throw e;
} Prevention
- Set content immediately after withName so the builder is never left without it.
- Build parts in a single expression to avoid conditional skips.
- Add a unit test asserting every generated part has content.
When it happens
Trigger: Calling EntityPart.withName("p").mediaType(...).build() without ever invoking content(...), or calling content() inside a code branch that was skipped at runtime.
Common situations: Dynamic multipart assembly where a part is added but its content assignment happens under a condition; copy-pasted builder code where the content line was deleted; wrapper APIs that forget to forward content.
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/5060f49b69afd0c5.
Report an issue: GitHub.