flowable/flowable-engine · error · FlowableIllegalStateException
Cannot set both body and body bytes
Error message
Cannot set both body and body bytes
What it means
HttpRequest forbids combining a String body with raw bodyBytes. Since the two body representations are mutually exclusive, setBody throws FlowableIllegalStateException if bodyBytes has already been set. This prevents ambiguity about which payload to send.
Solutions
- Choose one representation: remove the setBodyBytes call if you want a String body (or vice versa)
- Create a new HttpRequest instance instead of reusing one configured for a different payload type
- Extract request-building into a single code path that sets exactly one body form
Example fix
// before
request.setBodyBytes(data);
request.setBody("{\"ok\":true}"); // throws
// after
request.setBodyBytes(data); // keep bytes only
// or: request.setBody("{\"ok\":true}"); // keep string only Defensive patterns
Strategy: validation
Validate before calling
// guard before setting a String body
if (request.getBodyBytes() != null) {
throw new IllegalStateException("Request already has bodyBytes; pick one payload type");
}
request.setBody(body); Type guard
boolean canSetStringBody(HttpRequest r) { return r.getBodyBytes() == null; } Try / catch
try {
request.setBody(body);
} catch (FlowableIllegalStateException e) {
request = new HttpRequest(); // rebuild with a single payload type
request.setBody(body);
} Prevention
- Pick one payload mode (body | bodyBytes | form | multipart) per request up front
- Never reuse a configured HttpRequest across payload styles
- Check getBodyBytes()/getMultiValueParts()/getFormParameters() before setting a body
- Centralize request building in one helper
When it happens
Trigger: Calling request.setBody(jsonString) after a previous call to request.setBodyBytes(byteArray) on the same HttpRequest instance.
Common situations: Building one request object across code paths where one branch sets bytes (file upload) and another sets a String (JSON payload); refactoring code that switched body representations without clearing the other.
Related errors
- Cannot set both body and form parameters
- Cannot set both body and multi value parts
- Cannot set both body bytes and form parameters
- Cannot set both body bytes and multi value parts
- A non-null value is required for one of timeDate…
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/8ffd66516ecce6fb.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java:103
public HttpHeaders getSecureHttpHeaders() {
return secureHttpHeaders;
}
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)