{"record":{"id":"8ef5530e95fefbee","repo":"quarkusio/quarkus","slug":"malformed-quality-value","errorCode":null,"errorMessage":"Malformed quality value.","messagePattern":"Malformed quality value\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/request/QualityValue.java","lineNumber":84,"sourceCode":"    @Override\n    public float floatValue() {\n        return (float) WEIGHT / 1000f;\n    }\n\n    @Override\n    public int intValue() {\n        return WEIGHT;\n    }\n\n    @Override\n    public long longValue() {\n        return WEIGHT;\n    }\n\n    private static int parseAsInteger(String value) {\n        int length = value.length();\n        if (length == 0 || length > 5)\n            throw new BadRequestException(MALFORMED_VALUE_MESSAGE);\n        if (length > 1 && value.charAt(1) != '.')\n            throw new BadRequestException(MALFORMED_VALUE_MESSAGE);\n        int firstCharacter = value.codePointAt(0);\n        if (firstCharacter == '1') {\n            for (int i = 2; i < length; ++i)\n                if (value.charAt(i) != '0')\n                    throw new BadRequestException(MALFORMED_VALUE_MESSAGE);\n            return 1000;\n        } else if (firstCharacter == '0') {\n            int weight = 0;\n            for (int i = 2; i < 5; ++i) {\n                weight *= 10;\n                if (i < length) {\n                    int digit = value.codePointAt(i) - '0';\n                    if (digit < 0 || digit > 9)\n                        throw new BadRequestException(MALFORMED_VALUE_MESSAGE);\n                    weight += digit;\n                }","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/request/QualityValue.java#L66-L102","documentation":"QualityValue.parseAsInteger() validates q-values: 1–5 chars, single-digit form or d.dd form (digit, dot, up to 3 digits). Values failing these structural rules throw this BadRequestException (MALFORMED_VALUE_MESSAGE).","triggerScenarios":"q= parameter values like '10', '1.2345', '.5', 'q=abc', 'q=2.0' (>1) encountered while parsing Accept-style headers.","commonSituations":"Clients emitting weights outside 0–1 (e.g. 'q=2'); locale-formatted decimals; hand-written tests with arbitrary strings as q values.","solutions":["Use a valid q value between 0 and 1: 0, 0.5, 0.999, 1 (max 3 decimal digits)","Remove the q parameter entirely to use the default quality","Fix the client library that formats quality weights"],"exampleFix":"// before\nAccept: application/json;q=10\n// after\nAccept: application/json;q=1.0","handlingStrategy":"validation","validationCode":"boolean isValidQValue(String q) {\n    return q != null && q.matches(\"[01](\\.[0-9]{1,3})?\");\n}","typeGuard":"boolean isQualityValue(String v) {\n    if (v == null || v.isEmpty() || v.length() > 5) return false;\n    return v.matches(\"[01](\\.[0-9]{1,3})?\");\n}","tryCatchPattern":"try {\n    QualityValue qv = QualityValue.valueOf(q);\n} catch (BadRequestException e) {\n    QualityValue qv = QualityValue.DEFAULT;\n}","preventionTips":["Clamp computed weights to [0,1] with at most 3 decimals","Never emit integers >= 2 as q values","Use locale-independent formatting (Locale.ROOT) when serializing decimals"],"tags":["http","quality-value","accept-header"],"backgroundTag":"malformed-http-header","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"}