flowable/flowable-engine · error · FlowableIllegalStateException

Cannot set both body bytes and multi value parts

Error message

Cannot set both body bytes and multi value parts

What it means

HttpRequest forbids combining raw bodyBytes with multipart parts. setBodyBytes throws FlowableIllegalStateException when multiValueParts is non-empty; a request is either a raw byte payload or multipart-encoded, never both.

Solutions

  1. Skip setBodyBytes and attach the bytes as a multi value part (MultiValuePart.fromBytes) instead
  2. Remove the addMultiValuePart calls if a plain byte body is intended
  3. Build multipart requests exclusively through addMultiValuePart

Example fix

// before
request.addMultiValuePart(part);
request.setBodyBytes(bytes); // throws
// after
request.addMultiValuePart(MultiValuePart.fromBytes(bytes, "file.bin"));
Defensive patterns

Strategy: validation

Validate before calling

if (request.getMultiValueParts() != null && !request.getMultiValueParts().isEmpty()) {
    throw new IllegalStateException("Request is multipart; use MultiValuePart.fromBytes instead");
}
request.setBodyBytes(bytes);

Type guard

boolean canSetByteBody(HttpRequest r) {
    return r.getMultiValueParts() == null || r.getMultiValueParts().isEmpty();
}

Try / catch

try {
    request.setBodyBytes(bytes);
} catch (FlowableIllegalStateException e) {
    request = new HttpRequest();
    request.addMultiValuePart(MultiValuePart.fromBytes(bytes, "payload.bin"));
}

Prevention

When it happens

Trigger: Calling request.setBodyBytes(bytes) after one or more addMultiValuePart(...) calls on the same instance.

Common situations: Multipart file upload where a developer additionally tries to set raw bytes; generic request-builder helpers that always set a byte body even for multipart requests.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/cc2167e86e363440. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java:128

    }

    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");
        }

View on GitHub (pinned to d6d39ce1c6)