flowable/flowable-engine · error · FlowableIllegalStateException
Cannot set both body and multi value parts
Error message
Cannot set both body and multi value parts
What it means
HttpRequest forbids combining a String body with multi value (multipart) parts. setBody throws FlowableIllegalStateException when multipart parts have already been added, because a request cannot carry both a plain body and multipart form data.
Solutions
- Remove the setBody call and pass any extra fields as additional multi value parts
- If a plain body is needed, build a separate HttpRequest without addMultiValuePart calls
- Clear/reset the request (new instance) before switching payload styles
Example fix
// before
request.addMultiValuePart(MultiValuePart.fromBytes(file, "f.bin"));
request.setBody("meta"); // throws
// after
request.addMultiValuePart(MultiValuePart.fromString("meta", "meta.txt")); Defensive patterns
Strategy: validation
Validate before calling
if (request.getMultiValueParts() != null && !request.getMultiValueParts().isEmpty()) {
throw new IllegalStateException("Request is multipart; cannot also set a String body");
}
request.setBody(body); Type guard
boolean canSetStringBody(HttpRequest r) {
return r.getMultiValueParts() == null || r.getMultiValueParts().isEmpty();
} Try / catch
try {
request.setBody(body);
} catch (FlowableIllegalStateException e) {
request = new HttpRequest();
request.setBody(body); // drop multipart parts
} Prevention
- Attach extra data as additional multi value parts rather than a String body
- Use a fresh HttpRequest when switching between multipart and plain body
- Verify getMultiValueParts() is empty before calling setBody
- Keep multipart requests built solely via addMultiValuePart
When it happens
Trigger: Calling request.setBody(text) after request.addMultiValuePart(part) was used on the same instance.
Common situations: Adding a file part for an upload and then trying to also set a JSON/plain body on the same request; reusing a request object configured for multipart in a plain-body context.
Related errors
- Cannot set both body bytes and multi value parts
- Cannot set both body and body bytes
- Cannot set both body and form parameters
- Cannot set both body bytes and form parameters
- Cannot set both form parameters and multi value parts
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/01a70a0f2ee22b7f.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java:105
}
public String getSecureHttpHeadersAsString() {
return secureHttpHeaders != null ? secureHttpHeaders.formatAsString(true) : null;
}
public void setSecureHttpHeaders(HttpHeaders secureHttpHeaders) {
this.secureHttpHeaders = secureHttpHeaders;
}
public String getBody() {
return body;
}
public void setBody(String body) {
if (bodyBytes != null) {
throw new FlowableIllegalStateException("Cannot set both body and body bytes");
} else if (multiValueParts != null && !multiValueParts.isEmpty()) {
throw new FlowableIllegalStateException("Cannot set both body and multi value parts");
} else if (formParameters != null && !formParameters.isEmpty()) {
throw new FlowableIllegalStateException("Cannot set both body and form parameters");
}
this.body = body;
}
public String getBodyEncoding() {
return bodyEncoding;
}
public void setBodyEncoding(String bodyEncoding) {
this.bodyEncoding = bodyEncoding;
}
public byte[] getBodyBytes() {
return bodyBytes;
}
View on GitHub (pinned to d6d39ce1c6)