apache/kafka · error · NumberFormatException
${about}: expected a floating point type, but got ${nodeType
Error message
${about}: expected a floating point type, but got ${nodeType} What it means
Thrown by MessageUtil.jsonNodeToDouble when the JsonNode is not a floating-point number. Note Jackson's strictness here: an integer JSON literal like 5 reports isFloatingPointNumber()==false (it is an IntNode), so even numeric values must be written with a fractional part (5.0) to be accepted. Used for `float64`/double protocol fields such as client metrics or quota percentages.
Source
Thrown at clients/src/main/java/org/apache/kafka/common/protocol/MessageUtil.java:180
}
}
public static byte[] jsonNodeToBinary(JsonNode node, String about) {
try {
byte[] value = node.binaryValue();
if (value == null) {
throw new IllegalArgumentException(about + ": expected Base64-encoded binary data.");
}
return value;
} catch (IOException e) {
throw new UncheckedIOException(about + ": unable to retrieve Base64-encoded binary data", e);
}
}
public static double jsonNodeToDouble(JsonNode node, String about) {
if (!node.isFloatingPointNumber()) {
throw new NumberFormatException(about + ": expected a floating point " +
"type, but got " + node.getNodeType());
}
return node.asDouble();
}
public static byte[] duplicate(byte[] array) {
if (array == null)
return null;
return Arrays.copyOf(array, array.length);
}
/**
* Compare two RawTaggedFields lists.
* A null list is equivalent to an empty one in this context.
*/
public static boolean compareRawTaggedFields(List<RawTaggedField> first,
List<RawTaggedField> second) {
if (first == null) {View on GitHub (pinned to c31c9215e1)
Solutions
- Rewrite the JSON value with a fractional part or exponent: 100 → 100.0, or 1e2.
- Use the 'about' prefix to find the field, then ensure the source emits a JSON floating-point token.
- If the value comes from a numeric serializer, force a double type at the source (e.g. writeDoubleValue in Jackson, or printf '%f').
- Validate the JSON against the generated Message schema to catch integer-vs-double mismatches early.
Example fix
// before
{"consumer_byte_rate": 1000}
// after
{"consumer_byte_rate": 1000.0} Defensive patterns
Strategy: type-guard
Validate before calling
if (node == null || !node.isFloatingPointNumber()) throw new IllegalArgumentException("field must be a JSON float/double"); Type guard
node != null && node.isFloatingPointNumber()
Try / catch
try { double d = MessageUtil.jsonNodeToDouble(node, about); }
catch (NumberFormatException e) { /* non-float JSON value in double field; reject */ } Prevention
- Emit floating-point fields as JSON numbers with a fractional or exponent part.
- Do not send integer-only numbers where a double is expected; cast at the source.
- Avoid NaN/Infinity literals unless your JSON writer supports them and the consumer agrees.
When it happens
Trigger: A JSON value supplied for a double field is anything other than a JSON number with a fractional component or exponent: an integer literal (5), a string ('1.5'), a boolean, null, array, or object. node.isFloatingPointNumber()==false and line 180 throws NumberFormatException carrying the actual node type.
Common situations: Writing "value": 100 where the schema expects a double — JSON parsers preserve the syntactic form, so 100 stays an IntNode; passing percentage quotas as whole numbers; emitting metrics from a tool that elides trailing '.0'; quoting the number as a string from a UI input.
Related errors
- ${about}: expected an integer or string type, but got ${node
- ${about}: value ${value} does not fit in a 32-bit unsigned i
- ${about}: failed to parse hexadecimal number: ${cause}
- ${about}: failed to parse number: ${cause}
- ${about}: expected Base64-encoded binary data.
AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03).
Data as JSON: /data/errors/693d7eba99e42551.json.
Report an issue: GitHub.