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

  1. Encode the data as form parameters instead of raw bytes, or clear the form parameters first
  2. If bytes are required, start a new HttpRequest without form parameters
  3. 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

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


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)