{"record":{"id":"cc2167e86e363440","repo":"flowable/flowable-engine","slug":"cannot-set-both-body-bytes-and-multi-value-parts","errorCode":null,"errorMessage":"Cannot set both body bytes and multi value parts","messagePattern":"Cannot set both body bytes 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":128,"sourceCode":"    }\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\n    public void setBodyBytes(byte[] bodyBytes) {\n        if (body != 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 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        }","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java#L110-L146","documentation":"HttpRequest forbids combining raw bodyBytes with multipart parts. setBodyBytes throws FlowableIllegalStateException when multiValueParts is non-empty; a request is either a raw byte payload or multipart-encoded, never both.","triggerScenarios":"Calling request.setBodyBytes(bytes) after one or more addMultiValuePart(...) calls on the same instance.","commonSituations":"Multipart file upload where a developer additionally tries to set raw bytes; generic request-builder helpers that always set a byte body even for multipart requests.","solutions":["Skip setBodyBytes and attach the bytes as a multi value part (MultiValuePart.fromBytes) instead","Remove the addMultiValuePart calls if a plain byte body is intended","Build multipart requests exclusively through addMultiValuePart"],"exampleFix":"// before\nrequest.addMultiValuePart(part);\nrequest.setBodyBytes(bytes); // throws\n// after\nrequest.addMultiValuePart(MultiValuePart.fromBytes(bytes, \"file.bin\"));","handlingStrategy":"validation","validationCode":"if (request.getMultiValueParts() != null && !request.getMultiValueParts().isEmpty()) {\n    throw new IllegalStateException(\"Request is multipart; use MultiValuePart.fromBytes instead\");\n}\nrequest.setBodyBytes(bytes);","typeGuard":"boolean canSetByteBody(HttpRequest r) {\n    return r.getMultiValueParts() == null || r.getMultiValueParts().isEmpty();\n}","tryCatchPattern":"try {\n    request.setBodyBytes(bytes);\n} catch (FlowableIllegalStateException e) {\n    request = new HttpRequest();\n    request.addMultiValuePart(MultiValuePart.fromBytes(bytes, \"payload.bin\"));\n}","preventionTips":["Wrap raw bytes as MultiValuePart.fromBytes when the request is multipart","Never combine setBodyBytes with addMultiValuePart on one request","Check getMultiValueParts() before setBodyBytes","Keep multipart construction in a dedicated code path"],"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"}