{"record":{"id":"6927a07b8c1b73ba","repo":"flowable/flowable-engine","slug":"cannot-set-both-multi-value-parts-and-form-paramet","errorCode":null,"errorMessage":"Cannot set both multi value parts and form parameters","messagePattern":"Cannot set both multi value parts and form parameters","errorType":"validation","errorClass":"FlowableIllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java","lineNumber":163,"sourceCode":"            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\");\n        }\n        if (formParameters == null) {\n            formParameters = new LinkedHashMap<>();\n        }\n        formParameters.computeIfAbsent(key, k -> new ArrayList<>()).add(value);\n    }\n\n    public int getTimeout() {\n        return timeout;\n    }\n\n    public void setTimeout(int timeout) {\n        this.timeout = timeout;\n    }\n\n    public boolean isNoRedirects() {\n        return noRedirects;\n    }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java#L145-L181","documentation":"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.","triggerScenarios":"Calling HttpRequest.addFormParameter(key, value) after one or more addMultiValuePart(part) calls on the same instance (multiValueParts non-null and non-empty).","commonSituations":"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.","solutions":["Replace the addFormParameter call with addMultiValuePart(new MultiValuePart(key, value.getBytes())) to add the field to the multipart body.","Clear/rebuild the request without the multi value parts if a urlencoded form post is what you want.","Use two distinct HttpRequest instances for the two encodings."],"exampleFix":"// before\nrequest.addMultiValuePart(new MultiValuePart(\"file\", bytes));\nrequest.addFormParameter(\"field\", \"value\"); // throws\n\n// after\nrequest.addMultiValuePart(new MultiValuePart(\"file\", bytes));\nrequest.addMultiValuePart(new MultiValuePart(\"field\", \"value\".getBytes()));","handlingStrategy":"validation","validationCode":"if (request.getMultiValueParts() != null && !request.getMultiValueParts().isEmpty()) {\n    throw new IllegalStateException(\"Cannot add form parameters: multi value parts already set\");\n}\nrequest.addFormParameter(key, value);","typeGuard":"boolean canAddFormParameter(HttpRequest r) {\n    return r.getMultiValueParts() == null || r.getMultiValueParts().isEmpty();\n}","tryCatchPattern":"try {\n    request.addFormParameter(key, value);\n} catch (FlowableIllegalStateException e) {\n    request.addMultiValuePart(new MultiValuePart(key, value.getBytes()));\n}","preventionTips":["In multipart requests, add every field (including text fields) via addMultiValuePart","Keep form-post and multipart request builders in separate helpers","Document the chosen encoding at the call site to prevent mixed usage"],"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"}