apache/kafka · error · ConfigException
Expected value to be a 64-bit integer (long), but it was a v
Error message
Expected value to be a 64-bit integer (long), but it was a value.getClass().getName()
What it means
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.
Source
Thrown at clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java:760
throw new ConfigException(name, value, "Expected value to be a 32-bit integer, but it was a " + value.getClass().getName());
}
case SHORT:
if (value instanceof Short) {
return value;
} else if (value instanceof String) {
return Short.parseShort(trimmed);
} else {
throw new ConfigException(name, value, "Expected value to be a 16-bit integer (short), but it was a " + value.getClass().getName());
}
case LONG:
if (value instanceof Integer)
return ((Integer) value).longValue();
if (value instanceof Long)
return value;
else if (value instanceof String)
return Long.parseLong(trimmed);
else
throw new ConfigException(name, value, "Expected value to be a 64-bit integer (long), but it was a " + value.getClass().getName());
case DOUBLE:
if (value instanceof Number)
return ((Number) value).doubleValue();
else if (value instanceof String)
return Double.parseDouble(trimmed);
else
throw new ConfigException(name, value, "Expected value to be a double, but it was a " + value.getClass().getName());
case LIST:
if (value instanceof List)
return value;
else if (value instanceof String)
if (trimmed.isEmpty())
return List.of();
else
return Arrays.asList(COMMA_WITH_WHITESPACE.split(trimmed, -1));
else
throw new ConfigException(name, value, "Expected a comma separated list.");
case CLASS:View on GitHub (pinned to c31c9215e1)
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.
Example fix
// before props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 5000.0); // Double -> ConfigException // after props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, 5000L); // Long // or props.put(ProducerConfig.MAX_BLOCK_MS_CONFIG, "5000"); // String
Defensive patterns
Strategy: type-guard
Validate before calling
Object v = rawValue;
if (!(v instanceof Long) && !(v instanceof Integer) && !(v instanceof String)) {
throw new IllegalArgumentException("config '" + key + "' must be a long, int, or numeric string");
}
if (v instanceof String) {
Long.parseLong(((String) v).trim()); // probe-parse to surface NumberFormatException early
} Type guard
public static boolean isLongValue(Object v) {
if (v instanceof Long || v instanceof Integer) return true;
if (v instanceof String) {
try { Long.parseLong(((String) v).trim()); return true; }
catch (NumberFormatException e) { return false; }
}
return false;
} Try / catch
try {
configDef.parse(configs);
} catch (ConfigException e) {
if (e.getMessage().contains("Expected value to be a 64-bit integer")) {
// fix the offending key in `configs` and retry, or surface to caller
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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".
Common situations: 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.
Related errors
- Expected value to be a double, but it was a value.getClass()
- Expected a comma separated list.
- Expected a Class instance or class name.
- Invalid timestamp type {}
- Invalid url in bootstrap.servers: {url}
AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03).
Data as JSON: /data/errors/4fac845bb4ca6b70.json.
Report an issue: GitHub.