quarkusio/quarkus · error · WebApplicationException

Media type %s value must be a float: %s

Error message

Media type %s value must be a float: %s

What it means

MediaTypeHelper.getQTypeWithParamInfo attempts Float.parseFloat on the media type's q-type parameter; if the value is not a valid float it converts the NumberFormatException into a WebApplicationException with HTTP 400 BAD_REQUEST. This enforces that quality parameters are decimal numbers per HTTP specification.

Source

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

    public static String toString(MediaType mediaType) {
        return MediaTypeHeaderDelegate.INSTANCE.toString(mediaType);
    }

    private static float getQTypeWithParamInfo(MediaType type, String parameterName) {
        if (type.getParameters() != null) {
            String val = type.getParameters().get(parameterName);
            try {
                if (val != null) {
                    float rtn = Float.parseFloat(val);
                    if (rtn > 1.0F)
                        throw new WebApplicationException(
                                String.format("Media type %s greater than 1: %s", parameterName, type),
                                Response.Status.BAD_REQUEST);
                    return rtn;
                }
            } catch (NumberFormatException e) {
                throw new WebApplicationException(
                        String.format("Media type %s value must be a float: %s", parameterName, type),
                        Response.Status.BAD_REQUEST);
            }
        }
        return 2.0f;
    }

    public static float getQWithParamInfo(MediaType type) {
        return getQTypeWithParamInfo(type, "q");
    }

    /**
     * subtypes like application/*+xml
     *
     * @param subtype subtype
     * @return true if subtype is composite
     */
    public static boolean isCompositeWildcardSubtype(String subtype) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Fix the q parameter to a plain decimal using a dot, e.g. q=0.9
  2. Remove the malformed parameter entirely if quality is irrelevant
  3. If building headers programmatically, format floats with Locale.ROOT so a comma decimal separator is never emitted

Example fix

// before
String q = String.format("%.1f", weight); // may yield '0,9' in some locales
builder.header("Accept", "application/json;q=" + q);
// after
String q = String.format(Locale.ROOT, "%.1f", weight);
builder.header("Accept", "application/json;q=" + q);
Defensive patterns

Strategy: validation

Validate before calling

Matcher m = java.util.regex.Pattern.compile(";\\s*q\\s*=\\s*([^"]+)").matcher(mediaType);
if (m.find()) Float.parseFloat(m.group(1).trim().replace(',', '.')); // throws early if invalid

Try / catch

try { /* negotiation call */ } catch (WebApplicationException e) { if (e.getResponse().getStatus() == 400) { /* strip q param and retry */ } else throw e; }

Prevention

When it happens

Trigger: Sending a header like 'application/xml;q=high', 'text/plain;q=', or 'application/json;q=0,9' (comma decimal separator) during content negotiation via getQWithParamInfo.

Common situations: Locale-mistaken decimal commas (0,9 vs 0.9); symbolic weights ('q=high', 'q=normal'); truncated or corrupted headers from proxies; template placeholders left unrendered (q=${weight}).

Related errors


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