quarkusio/quarkus · error · WebApplicationException

media type weighted language q must be a float: ${lang}

Error message

media type weighted language q must be a float: ${lang}

What it means

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.

Source

Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/WeightedLanguage.java:94

            int start = 0;
            while (start < params.length()) {
                start = HeaderParameterParser.setParam(typeParams, params, start);
            }
        }
        return new WeightedLanguage(lang, typeParams);
    }

    private static float getQWithParamInfo(WeightedLanguage lang, String val) {
        try {
            if (val != null) {
                float rtn = Float.valueOf(val);
                if (rtn > 1.0F)
                    throw new WebApplicationException("q value cannot be greater than one: " + (lang.toString()),
                            Response.Status.BAD_REQUEST);
                return rtn;
            }
        } catch (NumberFormatException e) {
            throw new WebApplicationException("media type weighted language q must be a float: " + (lang.toString()),
                    Response.Status.BAD_REQUEST);
        }
        return 1.0f;
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Send only decimal q values with a dot, e.g. "en;q=0.8"
  2. Rewrite/validate the Accept-Language header in a ContainerRequestFilter before parsing
  3. Fix or upgrade the buggy client/proxy producing the malformed header
  4. Catch WebApplicationException and fall back to a default language

Example fix

// before
Accept-Language: de;q=0,9
// after
Accept-Language: de;q=0.9
Defensive patterns

Strategy: try-catch

Validate before calling

static boolean isFloat(String s) {
    try { Float.parseFloat(s); return true; } catch (NumberFormatException e) { return false; }
}
// validate each 'q=<v>' token with isFloat before sending

Try / catch

try {
    return WeightedLanguage.parse(header);
} catch (WebApplicationException e) {
    if (e.getResponse().getStatus() == 400 && e.getMessage() != null && e.getMessage().contains("q must be a float")) {
    return Collections.emptyList(); // fall back to no language preference
    } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/0088c92da99d8115. Report an issue: GitHub.