{"record":{"id":"0088c92da99d8115","repo":"quarkusio/quarkus","slug":"media-type-weighted-language-q-must-be-a-float","errorCode":null,"errorMessage":"media type weighted language q must be a float: ${lang}","messagePattern":"media type weighted language q must be a float: (.+?)","errorType":"http","errorClass":"WebApplicationException","httpStatus":400,"severity":"error","filePath":"independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/WeightedLanguage.java","lineNumber":94,"sourceCode":"            int start = 0;\n            while (start < params.length()) {\n                start = HeaderParameterParser.setParam(typeParams, params, start);\n            }\n        }\n        return new WeightedLanguage(lang, typeParams);\n    }\n\n    private static float getQWithParamInfo(WeightedLanguage lang, String val) {\n        try {\n            if (val != null) {\n                float rtn = Float.valueOf(val);\n                if (rtn > 1.0F)\n                    throw new WebApplicationException(\"q value cannot be greater than one: \" + (lang.toString()),\n                            Response.Status.BAD_REQUEST);\n                return rtn;\n            }\n        } catch (NumberFormatException e) {\n            throw new WebApplicationException(\"media type weighted language q must be a float: \" + (lang.toString()),\n                    Response.Status.BAD_REQUEST);\n        }\n        return 1.0f;\n    }\n\n    @Override\n    public boolean equals(Object obj) {\n        return super.equals(obj);\n    }\n\n    @Override\n    public int hashCode() {\n        return super.hashCode();\n    }\n}\n","sourceCodeStart":76,"sourceCodeEnd":110,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/WeightedLanguage.java#L76-L110","documentation":"WeightedLanguage.getQWithParamInfo parses the q parameter of a language range with Float.valueOf. If the q value is not a valid float, the NumberFormatException is converted to a WebApplicationException with HTTP 400 Bad Request. This keeps malformed Accept-Language headers from causing unhandled parse failures.","triggerScenarios":"An Accept-Language header containing a language with a non-numeric q, e.g. \"en;q=high\", \"de;q=\", or \"fr;q=1.0.0\"; the WeightedLanguage constructor triggers the parse via getQWithParamInfo.","commonSituations":"Typo'd hand-written headers in curl/tests; clients emitting locale-formatted decimals (q=0,8) that Float.valueOf cannot parse; buggy middleware injecting non-numeric quality values.","solutions":["Send only decimal q values with a dot, e.g. \"en;q=0.8\"","Rewrite/validate the Accept-Language header in a ContainerRequestFilter before parsing","Fix or upgrade the buggy client/proxy producing the malformed header","Catch WebApplicationException and fall back to a default language"],"exampleFix":"// before\nAccept-Language: de;q=0,9\n// after\nAccept-Language: de;q=0.9","handlingStrategy":"try-catch","validationCode":"static boolean isFloat(String s) {\n    try { Float.parseFloat(s); return true; } catch (NumberFormatException e) { return false; }\n}\n// validate each 'q=<v>' token with isFloat before sending","typeGuard":null,"tryCatchPattern":"try {\n    return WeightedLanguage.parse(header);\n} catch (WebApplicationException e) {\n    if (e.getResponse().getStatus() == 400 && e.getMessage() != null && e.getMessage().contains(\"q must be a float\")) {\n    return Collections.emptyList(); // fall back to no language preference\n    } else throw e;\n}","preventionTips":["Use dot-decimal notation for q values (q=0.9, never q=0,9)","Audit HTTP clients/proxies that rewrite Accept-Language headers","Add integration tests with edge-case headers (empty q, locale decimals)","Fail fast on the client side by parsing the header with the same rules before sending"],"tags":["http","content-negotiation","accept-language"],"backgroundTag":"invalid-q-value","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"}