flowable/flowable-engine · error · FlowableIllegalStateException

Cannot set both multi value parts and form parameters

Error message

Cannot set both multi value parts and form parameters

What it means

Form parameters and multi value parts are two different encodings of form data (urlencoded vs multipart). addFormParameter throws this FlowableIllegalStateException when multiValueParts already exist on the HttpRequest, because switching encodings mid-build is not supported.

Solutions

  1. Replace the addFormParameter call with addMultiValuePart(new MultiValuePart(key, value.getBytes())) to add the field to the multipart body.
  2. Clear/rebuild the request without the multi value parts if a urlencoded form post is what you want.
  3. Use two distinct HttpRequest instances for the two encodings.

Example fix

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

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

Strategy: validation

Validate before calling

if (request.getMultiValueParts() != null && !request.getMultiValueParts().isEmpty()) {
    throw new IllegalStateException("Cannot add form parameters: multi value parts already set");
}
request.addFormParameter(key, value);

Type guard

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

Try / catch

try {
    request.addFormParameter(key, value);
} catch (FlowableIllegalStateException e) {
    request.addMultiValuePart(new MultiValuePart(key, value.getBytes()));
}

Prevention

When it happens

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

Common situations: Starting a multipart file-upload request and then adding ordinary form fields via the wrong API; shared helper code that always calls addFormParameter for common fields; copy-pasting request-building code between form-post and multipart flows.

Related errors


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

Appendix: source

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

            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");
        }
        if (formParameters == null) {
            formParameters = new LinkedHashMap<>();
        }
        formParameters.computeIfAbsent(key, k -> new ArrayList<>()).add(value);
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public boolean isNoRedirects() {
        return noRedirects;
    }

View on GitHub (pinned to d6d39ce1c6)