flowable/flowable-engine · error · FlowableIllegalStateException
Cannot set both body and form parameters
Error message
Cannot set both body and form parameters
What it means
HttpRequest forbids combining a String body with form parameters. setBody throws FlowableIllegalStateException when formParameters is non-empty, since a request is either form-encoded or carries a raw body, not both.
Solutions
- Drop setBody and add the data as form parameters, or clear the form parameters before setting a body
- Use a fresh HttpRequest for the raw-body request
- Structure the builder code so a request picks exactly one payload mode (body | bodyBytes | form | multipart) up front
Example fix
// before
request.addFormParameter("a", "1");
request.setBody("raw"); // throws
// after
request.addFormParameter("a", "1"); // form mode only
// or: request.setBody("a=1&raw=..."); // encode manually in the body Defensive patterns
Strategy: validation
Validate before calling
if (request.getFormParameters() != null && !request.getFormParameters().isEmpty()) {
throw new IllegalStateException("Request is form-encoded; cannot also set a String body");
}
request.setBody(body); Type guard
boolean canSetStringBody(HttpRequest r) {
return r.getFormParameters() == null || r.getFormParameters().isEmpty();
} Try / catch
try {
request.setBody(body);
} catch (FlowableIllegalStateException e) {
request = new HttpRequest();
request.setBody(body); // form params dropped
} Prevention
- Encode extra fields as form parameters, not by concatenating into a raw body
- Do not mix form submission and raw body on one request
- Check getFormParameters() before setBody
- Build each request with exactly one payload mode
When it happens
Trigger: Calling request.setBody(text) after addFormParameter(...) populated form parameters on the same instance.
Common situations: Trying to send extra key/value fields plus a custom body on one request; reusing a request prepared for form submission in a raw-body context.
Related errors
- Cannot set both body bytes 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/a96037437ec6760a.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java:107
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;
}
public void setBodyBytes(byte[] bodyBytes) {
if (body != null) {View on GitHub (pinned to d6d39ce1c6)