{"id":"693d7eba99e42551","repo":"apache/kafka","slug":"about-expected-a-floating-point-type-but-got","errorCode":null,"errorMessage":"${about}: expected a floating point type, but got ${nodeType}","messagePattern":"(.+?): expected a floating point type, but got (.+?)","errorType":"exception","errorClass":"NumberFormatException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/protocol/MessageUtil.java","lineNumber":180,"sourceCode":"        }\n    }\n\n    public static byte[] jsonNodeToBinary(JsonNode node, String about) {\n        try {\n            byte[] value = node.binaryValue();\n            if (value == null) {\n                throw new IllegalArgumentException(about + \": expected Base64-encoded binary data.\");\n            }\n\n            return value;\n        } catch (IOException e) {\n            throw new UncheckedIOException(about + \": unable to retrieve Base64-encoded binary data\", e);\n        }\n    }\n\n    public static double jsonNodeToDouble(JsonNode node, String about) {\n        if (!node.isFloatingPointNumber()) {\n            throw new NumberFormatException(about + \": expected a floating point \" +\n                \"type, but got \" + node.getNodeType());\n        }\n        return node.asDouble();\n    }\n\n    public static byte[] duplicate(byte[] array) {\n        if (array == null)\n            return null;\n        return Arrays.copyOf(array, array.length);\n    }\n\n    /**\n     * Compare two RawTaggedFields lists.\n     * A null list is equivalent to an empty one in this context.\n     */\n    public static boolean compareRawTaggedFields(List<RawTaggedField> first,\n                                                 List<RawTaggedField> second) {\n        if (first == null) {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/protocol/MessageUtil.java#L162-L198","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n{\"consumer_byte_rate\": 1000}\n// after\n{\"consumer_byte_rate\": 1000.0}","handlingStrategy":"type-guard","validationCode":"if (node == null || !node.isFloatingPointNumber()) throw new IllegalArgumentException(\"field must be a JSON float/double\");","typeGuard":"node != null && node.isFloatingPointNumber()","tryCatchPattern":"try { double d = MessageUtil.jsonNodeToDouble(node, about); }\ncatch (NumberFormatException e) { /* non-float JSON value in double field; reject */ }","preventionTips":["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."],"tags":["kafka","protocol","json","serialization","type-mismatch","double","float64"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}