{"record":{"id":"1ebe13354ac18348","repo":"flowable/flowable-engine","slug":"cannot-set-both-body-bytes-and-form-parameters","errorCode":null,"errorMessage":"Cannot set both body bytes and form parameters","messagePattern":"Cannot set both body bytes 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":130,"sourceCode":"    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        }\n        if (multiValueParts == null) {\n            multiValueParts = new ArrayList<>();","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java#L112-L148","documentation":"HttpRequest forbids combining raw bodyBytes with form parameters. setBodyBytes throws FlowableIllegalStateException when formParameters is non-empty, because form-encoded and raw byte payloads are different content types.","triggerScenarios":"Calling request.setBodyBytes(bytes) after addFormParameter(...) calls on the same instance.","commonSituations":"Reusing a form-submission request for a binary upload; a shared builder that sets default form fields plus a byte body.","solutions":["Encode the data as form parameters instead of raw bytes, or clear the form parameters first","If bytes are required, start a new HttpRequest without form parameters","Set Content-Type appropriately for whichever single payload mode you keep"],"exampleFix":"// before\nrequest.addFormParameter(\"k\", \"v\");\nrequest.setBodyBytes(bytes); // throws\n// after\nrequest.setBodyBytes(bytes); // bytes only, no form params","handlingStrategy":"validation","validationCode":"if (request.getFormParameters() != null && !request.getFormParameters().isEmpty()) {\n    throw new IllegalStateException(\"Request is form-encoded; cannot also set bodyBytes\");\n}\nrequest.setBodyBytes(bytes);","typeGuard":"boolean canSetByteBody(HttpRequest r) {\n    return r.getFormParameters() == null || r.getFormParameters().isEmpty();\n}","tryCatchPattern":"try {\n    request.setBodyBytes(bytes);\n} catch (FlowableIllegalStateException e) {\n    request = new HttpRequest();\n    request.setBodyBytes(bytes);\n}","preventionTips":["Choose form-encoding or a raw byte body, never both","Check getFormParameters() before setBodyBytes","Use a new HttpRequest when the payload type changes","Set the matching Content-Type for the chosen mode"],"tags":["http","form","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"}