{"record":{"id":"d5db17d5cf07947f","repo":"quarkusio/quarkus","slug":"cannot-add-value-once-finalized","errorCode":null,"errorMessage":"Cannot add value once finalized","messagePattern":"Cannot add value once finalized","errorType":"exception","errorClass":"ErrorDataEncoderException","httpStatus":null,"severity":"error","filePath":"independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/PausableHttpPostRequestEncoder.java","lineNumber":510,"sourceCode":"        if (file.length != contentType.length && file.length != isText.length) {\n            throw new IllegalArgumentException(\"Different array length\");\n        }\n        for (int i = 0; i < file.length; i++) {\n            addBodyFileUpload(name, file[i], contentType[i], isText[i]);\n        }\n    }\n\n    /**\n     * Add the InterfaceHttpData to the Body list\n     *\n     * @throws NullPointerException\n     *         for data\n     * @throws ErrorDataEncoderException\n     *         if the encoding is in error or if the finalize were already done\n     */\n    public void addBodyHttpData(InterfaceHttpData data) throws ErrorDataEncoderException {\n        if (headerFinalized) {\n            throw new ErrorDataEncoderException(\"Cannot add value once finalized\");\n        }\n        bodyListDatas.add(checkNotNull(data, \"data\"));\n        if (!isMultipart) {\n            if (data instanceof Attribute attribute) {\n                try {\n                    // name=value& with encoded name and attribute\n                    String key = encodeAttribute(attribute.getName(), charset);\n                    String value = encodeAttribute(attribute.getValue(), charset);\n                    Attribute newattribute = factory.createAttribute(request, key, value);\n                    multipartHttpDatas.add(newattribute);\n                    globalBodySize += newattribute.getName().length() + 1 + newattribute.length() + 1;\n                } catch (IOException e) {\n                    throw new ErrorDataEncoderException(e);\n                }\n            } else if (data instanceof FileUpload fileUpload) {\n                // since not Multipart, only name=filename => Attribute\n                // name=filename& with encoded name and filename\n                String key = encodeAttribute(fileUpload.getName(), charset);","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/client/runtime/src/main/java/org/jboss/resteasy/reactive/client/impl/multipart/PausableHttpPostRequestEncoder.java#L492-L528","documentation":"Once finalizeRequest() has been called, the encoder's headers are written and no further body data can be added; addBodyHttpData throws ErrorDataEncoderException. The encoder is one-shot: finalize is terminal.","triggerScenarios":"Calling addBodyHttpData, addBodyAttribute or addBodyFileUpload after finalizeRequest() has completed.","commonSituations":"Reusing a single encoder to send multiple sequential requests; adding a late attribute in a callback after the request was already finalized.","solutions":["Create a new PausableHttpPostRequestEncoder for each request","Add all attributes and file uploads before calling finalizeRequest","Track a finalized flag in your code and rebuild the encoder when late data arrives"],"exampleFix":"// before\nencoder.finalizeRequest();\nencoder.addBodyAttribute(\"late\", \"value\");\n// after\nencoder.addBodyAttribute(\"late\", \"value\");\nencoder.finalizeRequest();","handlingStrategy":"try-catch","validationCode":"if (encoder.isFinalized()) { /* create a new encoder before adding data */ }","typeGuard":"null","tryCatchPattern":"try { encoder.addBodyHttpData(data); } catch (ErrorDataEncoderException e) { encoder = rebuildEncoder(request, bodyDataPlus(data)); }","preventionTips":["Strictly order: add all parts, then finalize once","Never reuse an encoder across requests or retries","Encapsulate encoder lifecycle in a single builder method"],"tags":["multipart","encoder-state","resteasy-reactive","lifecycle"],"backgroundTag":"object-already-finalized","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}