flowable/flowable-engine · error · FlowableIllegalStateException
Cannot set both body bytes and form parameters
Error message
Cannot set both body bytes and form parameters
What it means
HttpRequest forbids combining raw bodyBytes with form parameters. setBodyBytes throws FlowableIllegalStateException when formParameters is non-empty, because form-encoded and raw byte payloads are different content types.
Solutions
- Encode the data as form parameters instead of raw bytes, or clear the form parameters first
- If bytes are required, start a new HttpRequest without form parameters
- Set Content-Type appropriately for whichever single payload mode you keep
Example fix
// before
request.addFormParameter("k", "v");
request.setBodyBytes(bytes); // throws
// after
request.setBodyBytes(bytes); // bytes only, no form params Defensive patterns
Strategy: validation
Validate before calling
if (request.getFormParameters() != null && !request.getFormParameters().isEmpty()) {
throw new IllegalStateException("Request is form-encoded; cannot also set bodyBytes");
}
request.setBodyBytes(bytes); Type guard
boolean canSetByteBody(HttpRequest r) {
return r.getFormParameters() == null || r.getFormParameters().isEmpty();
} Try / catch
try {
request.setBodyBytes(bytes);
} catch (FlowableIllegalStateException e) {
request = new HttpRequest();
request.setBodyBytes(bytes);
} Prevention
- Choose form-encoding or a raw byte body, never both
- Check getFormParameters() before setBodyBytes
- Use a new HttpRequest when the payload type changes
- Set the matching Content-Type for the chosen mode
When it happens
Trigger: Calling request.setBodyBytes(bytes) after addFormParameter(...) calls on the same instance.
Common situations: Reusing a form-submission request for a binary upload; a shared builder that sets default form fields plus a byte body.
Related errors
- Cannot set both body and form parameters
- Cannot set both body and body bytes
- Cannot set both body and multi value parts
- 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/1ebe13354ac18348.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java:130
public String getBodyEncoding() {
return bodyEncoding;
}
public void setBodyEncoding(String bodyEncoding) {
this.bodyEncoding = bodyEncoding;
}
public byte[] getBodyBytes() {
return bodyBytes;
}
public void setBodyBytes(byte[] bodyBytes) {
if (body != null) {
throw new FlowableIllegalStateException("Cannot set both body and body bytes");
} else if (multiValueParts != null && !multiValueParts.isEmpty()) {
throw new FlowableIllegalStateException("Cannot set both body bytes and multi value parts");
} else if (formParameters != null && !formParameters.isEmpty()) {
throw new FlowableIllegalStateException("Cannot set both body bytes and form parameters");
}
this.bodyBytes = bodyBytes;
}
public Collection<MultiValuePart> getMultiValueParts() {
return multiValueParts;
}
public void addMultiValuePart(MultiValuePart part) {
if (body != null) {
throw new FlowableIllegalStateException("Cannot set both body and multi value parts");
} else if (bodyBytes != null) {
throw new FlowableIllegalStateException("Cannot set both body bytes and multi value parts");
} else if (formParameters != null && !formParameters.isEmpty()) {
throw new FlowableIllegalStateException("Cannot set both form parameters and multi value parts");
}
if (multiValueParts == null) {
multiValueParts = new ArrayList<>();View on GitHub (pinned to d6d39ce1c6)