{"record":{"id":"8ffd66516ecce6fb","repo":"flowable/flowable-engine","slug":"cannot-set-both-body-and-body-bytes","errorCode":null,"errorMessage":"Cannot set both body and body bytes","messagePattern":"Cannot set both body and body bytes","errorType":"validation","errorClass":"FlowableIllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java","lineNumber":103,"sourceCode":"    public HttpHeaders getSecureHttpHeaders() {\n        return secureHttpHeaders;\n    }\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;","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java#L85-L121","documentation":"HttpRequest forbids combining a String body with raw bodyBytes. Since the two body representations are mutually exclusive, setBody throws FlowableIllegalStateException if bodyBytes has already been set. This prevents ambiguity about which payload to send.","triggerScenarios":"Calling request.setBody(jsonString) after a previous call to request.setBodyBytes(byteArray) on the same HttpRequest instance.","commonSituations":"Building one request object across code paths where one branch sets bytes (file upload) and another sets a String (JSON payload); refactoring code that switched body representations without clearing the other.","solutions":["Choose one representation: remove the setBodyBytes call if you want a String body (or vice versa)","Create a new HttpRequest instance instead of reusing one configured for a different payload type","Extract request-building into a single code path that sets exactly one body form"],"exampleFix":"// before\nrequest.setBodyBytes(data);\nrequest.setBody(\"{\\\"ok\\\":true}\"); // throws\n// after\nrequest.setBodyBytes(data); // keep bytes only\n// or: request.setBody(\"{\\\"ok\\\":true}\"); // keep string only","handlingStrategy":"validation","validationCode":"// guard before setting a String body\nif (request.getBodyBytes() != null) {\n    throw new IllegalStateException(\"Request already has bodyBytes; pick one payload type\");\n}\nrequest.setBody(body);","typeGuard":"boolean canSetStringBody(HttpRequest r) { return r.getBodyBytes() == null; }","tryCatchPattern":"try {\n    request.setBody(body);\n} catch (FlowableIllegalStateException e) {\n    request = new HttpRequest(); // rebuild with a single payload type\n    request.setBody(body);\n}","preventionTips":["Pick one payload mode (body | bodyBytes | form | multipart) per request up front","Never reuse a configured HttpRequest across payload styles","Check getBodyBytes()/getMultiValueParts()/getFormParameters() before setting a body","Centralize request building in one helper"],"tags":["http","request","mutually-exclusive","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"}