{"record":{"id":"44246373b8a37093","repo":"flowable/flowable-engine","slug":"cannot-set-both-form-parameters-and-multi-value-pa","errorCode":null,"errorMessage":"Cannot set both form parameters and multi value parts","messagePattern":"Cannot set both form parameters and multi value parts","errorType":"validation","errorClass":"FlowableIllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java","lineNumber":145,"sourceCode":"        } else if (multiValueParts != null && !multiValueParts.isEmpty()) {\n            throw new FlowableIllegalStateException(\"Cannot set both body bytes and multi value parts\");\n        } else if (formParameters != null && !formParameters.isEmpty()) {\n            throw new FlowableIllegalStateException(\"Cannot set both body bytes and form parameters\");\n        }\n        this.bodyBytes = bodyBytes;\n    }\n\n    public Collection<MultiValuePart> getMultiValueParts() {\n        return multiValueParts;\n    }\n\n    public void addMultiValuePart(MultiValuePart part) {\n        if (body != null) {\n            throw new FlowableIllegalStateException(\"Cannot set both body and multi value parts\");\n        } else if (bodyBytes != null) {\n            throw new FlowableIllegalStateException(\"Cannot set both body bytes and multi value parts\");\n        } else if (formParameters != null && !formParameters.isEmpty()) {\n            throw new FlowableIllegalStateException(\"Cannot set both form parameters and multi value parts\");\n        }\n        if (multiValueParts == null) {\n            multiValueParts = new ArrayList<>();\n        }\n        multiValueParts.add(part);\n    }\n\n    public Map<String, List<String>> getFormParameters() {\n        return formParameters;\n    }\n\n    public void addFormParameter(String key, String value) {\n        if (body != null) {\n            throw new FlowableIllegalStateException(\"Cannot set both body and form parameters\");\n        } else if (bodyBytes != null) {\n            throw new FlowableIllegalStateException(\"Cannot set both body bytes and form parameters\");\n        } else if (multiValueParts != null && !multiValueParts.isEmpty()) {\n            throw new FlowableIllegalStateException(\"Cannot set both multi value parts and form parameters\");","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java#L127-L163","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Remove the addFormParameter calls and express those fields as MultiValuePart entries (multipart form fields).","Remove the addMultiValuePart call if the request is meant to be a plain form post.","Build a fresh HttpRequest instance for the multipart variant instead of reusing the form-parameter request."],"exampleFix":"// before\nrequest.addFormParameter(\"field\", \"value\");\nrequest.addMultiValuePart(new MultiValuePart(\"file\", bytes)); // throws\n\n// after\nrequest.addMultiValuePart(new MultiValuePart(\"field\", \"value\".getBytes()));\nrequest.addMultiValuePart(new MultiValuePart(\"file\", bytes));","handlingStrategy":"validation","validationCode":"if (request.getFormParameters() != null && !request.getFormParameters().isEmpty()) {\n    throw new IllegalStateException(\"Cannot add multi value parts: form parameters already set\");\n}\nrequest.addMultiValuePart(part);","typeGuard":"boolean canAddMultiValuePart(HttpRequest r) {\n    return r.getBody() == null && r.getBodyBytes() == null\n        && (r.getFormParameters() == null || r.getFormParameters().isEmpty());\n}","tryCatchPattern":"try {\n    request.addMultiValuePart(part);\n} catch (FlowableIllegalStateException e) {\n    // rebuild request with a single body representation\n}","preventionTips":["Pick one body encoding (form params vs multipart) before building the request","Centralize request building in one helper that enforces a single representation","Never reuse request-builder instances across different body styles"],"tags":["http","multipart","form-parameters","invalid-state"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}