quarkusio/quarkus · warning · BadRequestException
Malformed quality value.
Error message
Malformed quality value.
What it means
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).
Source
Thrown at independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/request/QualityValue.java:84
@Override
public float floatValue() {
return (float) WEIGHT / 1000f;
}
@Override
public int intValue() {
return WEIGHT;
}
@Override
public long longValue() {
return WEIGHT;
}
private static int parseAsInteger(String value) {
int length = value.length();
if (length == 0 || length > 5)
throw new BadRequestException(MALFORMED_VALUE_MESSAGE);
if (length > 1 && value.charAt(1) != '.')
throw new BadRequestException(MALFORMED_VALUE_MESSAGE);
int firstCharacter = value.codePointAt(0);
if (firstCharacter == '1') {
for (int i = 2; i < length; ++i)
if (value.charAt(i) != '0')
throw new BadRequestException(MALFORMED_VALUE_MESSAGE);
return 1000;
} else if (firstCharacter == '0') {
int weight = 0;
for (int i = 2; i < 5; ++i) {
weight *= 10;
if (i < length) {
int digit = value.codePointAt(i) - '0';
if (digit < 0 || digit > 9)
throw new BadRequestException(MALFORMED_VALUE_MESSAGE);
weight += digit;
}View on GitHub (pinned to e1c734241f)
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
Example fix
// before Accept: application/json;q=10 // after Accept: application/json;q=1.0
Defensive patterns
Strategy: validation
Validate before calling
boolean isValidQValue(String q) {
return q != null && q.matches("[01](\.[0-9]{1,3})?");
} Type guard
boolean isQualityValue(String v) {
if (v == null || v.isEmpty() || v.length() > 5) return false;
return v.matches("[01](\.[0-9]{1,3})?");
} Try / catch
try {
QualityValue qv = QualityValue.valueOf(q);
} catch (BadRequestException e) {
QualityValue qv = QualityValue.DEFAULT;
} Prevention
- 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
When it happens
Trigger: q= parameter values like '10', '1.2345', '.5', 'q=abc', 'q=2.0' (>1) encountered while parsing Accept-style headers.
Common situations: Clients emitting weights outside 0–1 (e.g. 'q=2'); locale-formatted decimals; hand-written tests with arbitrary strings as q values.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Malformed media type:
- IOException(e)
- OIDC discovery endpoint request failed
- Proxy type HTTP is required
- Response already committed
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/8ef5530e95fefbee.
Report an issue: GitHub.