{"id":"4fac845bb4ca6b70","repo":"apache/kafka","slug":"expected-value-to-be-a-64-bit-integer-long-but","errorCode":null,"errorMessage":"Expected value to be a 64-bit integer (long), but it was a value.getClass().getName()","messagePattern":"Expected value to be a 64-bit integer \\(long\\), but it was a value\\.getClass\\(\\)\\.getName\\(\\)","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java","lineNumber":760,"sourceCode":"                        throw new ConfigException(name, value, \"Expected value to be a 32-bit integer, but it was a \" + value.getClass().getName());\n                    }\n                case SHORT:\n                    if (value instanceof Short) {\n                        return value;\n                    } else if (value instanceof String) {\n                        return Short.parseShort(trimmed);\n                    } else {\n                        throw new ConfigException(name, value, \"Expected value to be a 16-bit integer (short), but it was a \" + value.getClass().getName());\n                    }\n                case LONG:\n                    if (value instanceof Integer)\n                        return ((Integer) value).longValue();\n                    if (value instanceof Long)\n                        return value;\n                    else if (value instanceof String)\n                        return Long.parseLong(trimmed);\n                    else\n                        throw new ConfigException(name, value, \"Expected value to be a 64-bit integer (long), but it was a \" + value.getClass().getName());\n                case DOUBLE:\n                    if (value instanceof Number)\n                        return ((Number) value).doubleValue();\n                    else if (value instanceof String)\n                        return Double.parseDouble(trimmed);\n                    else\n                        throw new ConfigException(name, value, \"Expected value to be a double, but it was a \" + value.getClass().getName());\n                case LIST:\n                    if (value instanceof List)\n                        return value;\n                    else if (value instanceof String)\n                        if (trimmed.isEmpty())\n                            return List.of();\n                        else\n                            return Arrays.asList(COMMA_WITH_WHITESPACE.split(trimmed, -1));\n                    else\n                        throw new ConfigException(name, value, \"Expected a comma separated list.\");\n                case CLASS:","sourceCodeStart":742,"sourceCodeEnd":778,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L742-L778","documentation":"Thrown by ConfigDef.parseType when a config key declared as Type.LONG receives a value that is neither Integer, Long, nor a String parseable by Long.parseLong. The library needs a 64-bit integral to honor the declared schema, so it refuses any other runtime type (e.g. Double, Boolean, List, or a custom object). The offending value's Java class name is appended to the message to make the mismatch obvious.","triggerScenarios":"Calling KafkaProducer/Consumer/AdminClient/KafkaStreams constructor (or ConfigDef.parse/validate) with a properties map where a LONG-typed config (e.g. max.block.ms, connections.max.idle.ms, reconnect.backoff.ms, request.timeout.ms, metadata.max.age.ms) is set to a non-integer/non-string object, or a string holding a decimal like \"5000.0\" rather than \"5000\".","commonSituations":"Loading config from a YAML/JSON/Typesafe Config library that returns doubles for unquoted numbers; passing a java.lang.Double or BigDecimal from a typed config POJO; env-var or CLI override that injected a float; Spring Boot @Value injecting a Double into a Long property; cross-version config where a time-in-ms key was previously int and the producer was upgraded.","solutions":["Set the property to a plain integer string (e.g. max.block.ms=5000) or pass a java.lang.Long/Integer value.","If the value flows through a typed config loader, force integer parsing before handing it to Kafka (Long.parseLong(String.valueOf(x))).","Quote numeric values in YAML/JSON configs so the loader yields a String rather than a Double, letting Long.parseLong succeed.","Audit overrides layered on top of defaults: a default of type Long overridden at runtime by a Double triggers this even when the default looks fine."],"exampleFix":"// before\nprops.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 5000.0); // Double -> ConfigException\n\n// after\nprops.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 5000L);   // Long\n// or\nprops.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, \"5000\");  // String","handlingStrategy":"type-guard","validationCode":"Object v = rawValue;\nif (!(v instanceof Long) && !(v instanceof Integer) && !(v instanceof String)) {\n    throw new IllegalArgumentException(\"config '\" + key + \"' must be a long, int, or numeric string\");\n}\nif (v instanceof String) {\n    Long.parseLong(((String) v).trim()); // probe-parse to surface NumberFormatException early\n}","typeGuard":"public static boolean isLongValue(Object v) {\n    if (v instanceof Long || v instanceof Integer) return true;\n    if (v instanceof String) {\n        try { Long.parseLong(((String) v).trim()); return true; }\n        catch (NumberFormatException e) { return false; }\n    }\n    return false;\n}","tryCatchPattern":"try {\n    configDef.parse(configs);\n} catch (ConfigException e) {\n    if (e.getMessage().contains(\"Expected value to be a 64-bit integer\")) {\n        // fix the offending key in `configs` and retry, or surface to caller\n    } else throw e;\n}","preventionTips":["Load config values from typed sources (Long/Integer) rather than passing arbitrary Objects through.","If config is sourced from String properties, explicitly convert numeric strings with Long.parseLong before adding them to the map.","Validate every numeric entry against a typed schema before calling ConfigDef.parse."],"tags":["config","type-mismatch","client","producer","consumer"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}