{"record":{"id":"255b93bdcf2e553f","repo":"quarkusio/quarkus","slug":"bad-request","errorCode":null,"errorMessage":"Bad Request","messagePattern":"Bad Request","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/providers/serialisers/ServerDefaultTextPlainBodyHandler.java","lineNumber":26,"sourceCode":"import jakarta.ws.rs.ProcessingException;\nimport jakarta.ws.rs.WebApplicationException;\nimport jakarta.ws.rs.core.MediaType;\nimport jakarta.ws.rs.core.Response;\n\nimport org.jboss.resteasy.reactive.common.providers.serialisers.DefaultTextPlainBodyHandler;\nimport org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo;\nimport org.jboss.resteasy.reactive.server.spi.ServerMessageBodyReader;\nimport org.jboss.resteasy.reactive.server.spi.ServerRequestContext;\n\n@Consumes(\"text/plain\")\npublic class ServerDefaultTextPlainBodyHandler extends DefaultTextPlainBodyHandler implements ServerMessageBodyReader<Object> {\n\n    @Override\n    protected void validateInput(String input) throws ProcessingException {\n        if (input.isEmpty()) {\n            // add an empty, non-null entity in order to ensure that the response will be used as is\n            // TODO: this seems to be an edge case, but perhaps it needs to be handled by RequestDeserializeHandler?\n            throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(\"\").build());\n        }\n    }\n\n    @Override\n    public boolean isReadable(Class<?> type, Type genericType, ResteasyReactiveResourceInfo lazyMethod,\n            MediaType mediaType) {\n        return super.isReadable(type, genericType, null, mediaType);\n    }\n\n    @Override\n    public Object readFrom(Class<Object> type, Type genericType, MediaType mediaType, ServerRequestContext context)\n            throws WebApplicationException, IOException {\n        return doReadFrom(type, mediaType, context.getInputStream());\n    }\n}\n","sourceCodeStart":8,"sourceCodeEnd":42,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/providers/serialisers/ServerDefaultTextPlainBodyHandler.java#L8-L42","documentation":"The default String body reader for text/plain input rejects an empty request body: ServerDefaultTextPlainBodyHandler.validateInput throws BadRequestException with an empty entity so the HTTP 400 response is returned as-is. Reading a String parameter from a request with no body is treated as a client error rather than producing null.","triggerScenarios":"A resource method taking a plain String (or text/plain) body parameter while the client sends an empty request body (Content-Length: 0 or empty streamed input) — validateInput receives input.isEmpty() == true.","commonSituations":"Clients posting with no body to endpoints expecting text/plain payloads; curl commands without -d; empty form fields mapped to String body; tests sending empty POST bodies.","solutions":["Send a non-empty body from the client (even a space or placeholder) when using text/plain String parameters","Change the resource method to read the raw InputStream or use Optional<String>-style handling if empty bodies are valid","Register a custom ServerMessageBodyReader for String that tolerates empty input","Use a different content type/handler (e.g. JSON with a default) when empty bodies should map to null"],"exampleFix":"// before (client)\ncurl -X POST http://localhost:8080/echo // empty body -> 400\n\n// after\ncurl -X POST -H \"Content-Type: text/plain\" -d \"hello\" http://localhost:8080/echo","handlingStrategy":"validation","validationCode":"// client-side: ensure the text/plain body is non-empty before POSTing\nif (body == null || body.isEmpty()) {\n    throw new IllegalArgumentException(\"text/plain endpoints reject an empty body\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return client.post(body);\n} catch (BadRequestException e) {\n    // 400 from empty text/plain body\n    return sendWithPlaceholderOrSkip(e);\n}","preventionTips":["Send a non-empty body when the endpoint consumes text/plain","Prefer reading InputStream or Optional-based handling when empty bodies are legitimate","Document the empty-body behavior in the endpoint contract","Set Content-Type explicitly so the right body handler runs"],"tags":["http-400","body-reading","text-plain","client-error"],"backgroundTag":"empty-request-body","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}