{"record":{"id":"01a70a0f2ee22b7f","repo":"flowable/flowable-engine","slug":"cannot-set-both-body-and-multi-value-parts","errorCode":null,"errorMessage":"Cannot set both body and multi value parts","messagePattern":"Cannot set both body 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":105,"sourceCode":"    }\n\n    public String getSecureHttpHeadersAsString() {\n        return secureHttpHeaders != null ? secureHttpHeaders.formatAsString(true) : null;\n    }\n\n    public void setSecureHttpHeaders(HttpHeaders secureHttpHeaders) {\n        this.secureHttpHeaders = secureHttpHeaders;\n    }\n\n    public String getBody() {\n        return body;\n    }\n\n    public void setBody(String body) {\n        if (bodyBytes != null) {\n            throw new FlowableIllegalStateException(\"Cannot set both body and body bytes\");\n        } else if (multiValueParts != null && !multiValueParts.isEmpty()) {\n            throw new FlowableIllegalStateException(\"Cannot set both body and multi value parts\");\n        } else if (formParameters != null && !formParameters.isEmpty()) {\n            throw new FlowableIllegalStateException(\"Cannot set both body and form parameters\");\n        }\n        this.body = body;\n    }\n\n    public String getBodyEncoding() {\n        return bodyEncoding;\n    }\n\n    public void setBodyEncoding(String bodyEncoding) {\n        this.bodyEncoding = bodyEncoding;\n    }\n\n    public byte[] getBodyBytes() {\n        return bodyBytes;\n    }\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java#L87-L123","documentation":"HttpRequest forbids combining a String body with multi value (multipart) parts. setBody throws FlowableIllegalStateException when multipart parts have already been added, because a request cannot carry both a plain body and multipart form data.","triggerScenarios":"Calling request.setBody(text) after request.addMultiValuePart(part) was used on the same instance.","commonSituations":"Adding a file part for an upload and then trying to also set a JSON/plain body on the same request; reusing a request object configured for multipart in a plain-body context.","solutions":["Remove the setBody call and pass any extra fields as additional multi value parts","If a plain body is needed, build a separate HttpRequest without addMultiValuePart calls","Clear/reset the request (new instance) before switching payload styles"],"exampleFix":"// before\nrequest.addMultiValuePart(MultiValuePart.fromBytes(file, \"f.bin\"));\nrequest.setBody(\"meta\"); // throws\n// after\nrequest.addMultiValuePart(MultiValuePart.fromString(\"meta\", \"meta.txt\"));","handlingStrategy":"validation","validationCode":"if (request.getMultiValueParts() != null && !request.getMultiValueParts().isEmpty()) {\n    throw new IllegalStateException(\"Request is multipart; cannot also set a String body\");\n}\nrequest.setBody(body);","typeGuard":"boolean canSetStringBody(HttpRequest r) {\n    return r.getMultiValueParts() == null || r.getMultiValueParts().isEmpty();\n}","tryCatchPattern":"try {\n    request.setBody(body);\n} catch (FlowableIllegalStateException e) {\n    request = new HttpRequest();\n    request.setBody(body); // drop multipart parts\n}","preventionTips":["Attach extra data as additional multi value parts rather than a String body","Use a fresh HttpRequest when switching between multipart and plain body","Verify getMultiValueParts() is empty before calling setBody","Keep multipart requests built solely via addMultiValuePart"],"tags":["http","multipart","mutually-exclusive","request"],"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"}