flowable/flowable-engine · error · FlowableIllegalStateException

Cannot set both form parameters and multi value parts

Error message

Cannot set both form parameters and multi value parts

What it means

HttpRequest enforces that a request body is expressed in exactly one way: a body object, raw body bytes, form parameters, or multi value parts (multipart). Calling addMultiValuePart when form parameters have already been added makes the request ambiguous, so the library throws FlowableIllegalStateException instead of producing an ill-formed HTTP request.

Solutions

  1. Remove the addFormParameter calls and express those fields as MultiValuePart entries (multipart form fields).
  2. Remove the addMultiValuePart call if the request is meant to be a plain form post.
  3. Build a fresh HttpRequest instance for the multipart variant instead of reusing the form-parameter request.

Example fix

// before
request.addFormParameter("field", "value");
request.addMultiValuePart(new MultiValuePart("file", bytes)); // throws

// after
request.addMultiValuePart(new MultiValuePart("field", "value".getBytes()));
request.addMultiValuePart(new MultiValuePart("file", bytes));
Defensive patterns

Strategy: validation

Validate before calling

if (request.getFormParameters() != null && !request.getFormParameters().isEmpty()) {
    throw new IllegalStateException("Cannot add multi value parts: form parameters already set");
}
request.addMultiValuePart(part);

Type guard

boolean canAddMultiValuePart(HttpRequest r) {
    return r.getBody() == null && r.getBodyBytes() == null
        && (r.getFormParameters() == null || r.getFormParameters().isEmpty());
}

Try / catch

try {
    request.addMultiValuePart(part);
} catch (FlowableIllegalStateException e) {
    // rebuild request with a single body representation
}

Prevention

When it happens

Trigger: Calling HttpRequest.addMultiValuePart(part) after one or more calls to addFormParameter(key, value) on the same HttpRequest instance (formParameters is non-null and non-empty).

Common situations: Building a request programmatically where form fields are added by one code path and a file upload part by another; copying an existing form-post request and appending a multipart file; migrating a request from application/x-www-form-urlencoded to multipart without clearing formParameters.

Related errors


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

Appendix: source

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

        } 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<>();
        }
        multiValueParts.add(part);
    }

    public Map<String, List<String>> getFormParameters() {
        return formParameters;
    }

    public void addFormParameter(String key, String value) {
        if (body != null) {
            throw new FlowableIllegalStateException("Cannot set both body and form parameters");
        } else if (bodyBytes != null) {
            throw new FlowableIllegalStateException("Cannot set both body bytes and form parameters");
        } else if (multiValueParts != null && !multiValueParts.isEmpty()) {
            throw new FlowableIllegalStateException("Cannot set both multi value parts and form parameters");

View on GitHub (pinned to d6d39ce1c6)