{"record":{"id":"a96037437ec6760a","repo":"flowable/flowable-engine","slug":"cannot-set-both-body-and-form-parameters","errorCode":null,"errorMessage":"Cannot set both body and form parameters","messagePattern":"Cannot set both body 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":107,"sourceCode":"    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\n    public void setBodyBytes(byte[] bodyBytes) {\n        if (body != null) {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-http-common/src/main/java/org/flowable/http/common/api/HttpRequest.java#L89-L125","documentation":"HttpRequest forbids combining a String body with form parameters. setBody throws FlowableIllegalStateException when formParameters is non-empty, since a request is either form-encoded or carries a raw body, not both.","triggerScenarios":"Calling request.setBody(text) after addFormParameter(...) populated form parameters on the same instance.","commonSituations":"Trying to send extra key/value fields plus a custom body on one request; reusing a request prepared for form submission in a raw-body context.","solutions":["Drop setBody and add the data as form parameters, or clear the form parameters before setting a body","Use a fresh HttpRequest for the raw-body request","Structure the builder code so a request picks exactly one payload mode (body | bodyBytes | form | multipart) up front"],"exampleFix":"// before\nrequest.addFormParameter(\"a\", \"1\");\nrequest.setBody(\"raw\"); // throws\n// after\nrequest.addFormParameter(\"a\", \"1\"); // form mode only\n// or: request.setBody(\"a=1&raw=...\"); // encode manually in the body","handlingStrategy":"validation","validationCode":"if (request.getFormParameters() != null && !request.getFormParameters().isEmpty()) {\n    throw new IllegalStateException(\"Request is form-encoded; cannot also set a String body\");\n}\nrequest.setBody(body);","typeGuard":"boolean canSetStringBody(HttpRequest r) {\n    return r.getFormParameters() == null || r.getFormParameters().isEmpty();\n}","tryCatchPattern":"try {\n    request.setBody(body);\n} catch (FlowableIllegalStateException e) {\n    request = new HttpRequest();\n    request.setBody(body); // form params dropped\n}","preventionTips":["Encode extra fields as form parameters, not by concatenating into a raw body","Do not mix form submission and raw body on one request","Check getFormParameters() before setBody","Build each request with exactly one payload 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"}