{"record":{"id":"ce85ad2d0735dc22","repo":"quarkusio/quarkus","slug":"invalid-char-value-str","errorCode":null,"errorMessage":"invalid char value: \" + str","messagePattern":"invalid char value: \" \\+ str","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/parameters/converters/CharParamConverter.java","lineNumber":9,"sourceCode":"package org.jboss.resteasy.reactive.server.core.parameters.converters;\n\npublic class CharParamConverter implements ParameterConverter {\n\n    @Override\n    public Object convert(Object parameter) {\n        String str = parameter.toString();\n        if (str.length() != 1) {\n            throw new IllegalArgumentException(\"invalid char value: \" + str);\n        }\n        return str.charAt(0);\n    }\n\n    public static class Supplier implements ParameterConverterSupplier {\n\n        @Override\n        public String getClassName() {\n            return CharParamConverter.class.getName();\n        }\n\n        @Override\n        public CharParamConverter get() {\n            return new CharParamConverter();\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/parameters/converters/CharParamConverter.java#L1-L27","documentation":"CharParamConverter.convert throws an IllegalArgumentException when converting a request parameter to a primitive char if the raw string does not contain exactly one character. Parameter converters translate string query/path/form/header values; only a 1-character string is a valid char. The exception typically surfaces as a 400 response.","triggerScenarios":"A query/path/header/form parameter mapped to a char receives an empty string or a string longer than one character, e.g. ?letter=ab or a missing-but-empty param.","commonSituations":"Clients sending multi-character values by mistake; empty query params (?x=); locale/data-entry issues; APIs where a 'code' field grew from one character to more.","solutions":["Send exactly one character for the parameter, or change the endpoint type to String and validate manually with a clear error message.","Use Character (wrapper) with an explicit null/length check if absence must be handled gracefully.","Add client-side validation enforcing max length 1 before the request.","If values can be legitimately longer, refactor the resource to String/enum."],"exampleFix":"// before\npublic Response get(@QueryParam(\"initial\") char initial)\n// after\npublic Response get(@QueryParam(\"initial\") String initial) {\n    if (initial == null || initial.length() != 1) throw new BadRequestException(\"initial must be a single char\");\n    char c = initial.charAt(0); ...\n}","handlingStrategy":"validation","validationCode":"if (raw == null || raw.length() != 1) { throw new BadRequestException(\"'initial' must be exactly one character\"); }","typeGuard":"boolean isSingleChar(String s) { return s != null && s.length() == 1; }","tryCatchPattern":"try { char c = (char) converter.convert(raw); } catch (IllegalArgumentException e) { return Response.status(400).entity(e.getMessage()).build(); }","preventionTips":["Validate param length client-side","Avoid char params for free-form input","Default to String and convert manually","Add tests for empty and multi-char values"],"tags":["rest","parameter-conversion","validation"],"backgroundTag":"invalid-parameter-conversion","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}