apache/kafka · error · ConfigException
Expected value to be a double, but it was a value.getClass()
Error message
Expected value to be a double, but it was a value.getClass().getName()
What it means
Thrown by ConfigDef.parseType for Type.DOUBLE when the supplied value is neither a Number nor a String. Doubles in Kafka configs (e.g. metrics.sample.window.ms is LONG, but broker metric/recording-level and some custom configs use DOUBLE) must be coerced from Number/String; anything else (Boolean, List, Class, Map) cannot be converted and is rejected with the actual class reported.
Source
Thrown at clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java:767
} 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:
if (value instanceof Class)
return value;
else if (value instanceof String) {
return Utils.loadClass(trimmed, Object.class);
} else
throw new ConfigException(name, value, "Expected a Class instance or class name.");
default:View on GitHub (pinned to c31c9215e1)
Solutions
- Provide the value as a numeric literal (Double, Integer, Long, etc.) or a numeric String like "0.5".
- If reading from external config, ensure the loader does not coerce the cell to a non-numeric type (quote it as a string if unsure).
- Check the ConfigDef entry for the key: confirm its declared Type is really DOUBLE and you are not confusing it with a STRING enum.
Example fix
// before
props.put("my.ratio", true); // Boolean -> ConfigException
// after
props.put("my.ratio", 0.5); // Double
props.put("my.ratio", "0.5"); Defensive patterns
Strategy: type-guard
Validate before calling
Object v = rawValue;
if (!(v instanceof Number) && !(v instanceof String)) {
throw new IllegalArgumentException("config '" + key + "' must be a Number or numeric string");
}
if (v instanceof String) {
Double.parseDouble(((String) v).trim());
} Type guard
public static boolean isDoubleValue(Object v) {
if (v instanceof Number) return true;
if (v instanceof String) {
try { Double.parseDouble(((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 double")) {
// coerce the value to a Number and retry
} else throw e;
} Prevention
- Store DOUBLE config values as Double, not as generic Objects.
- Treat string inputs for doubles as transient; convert to Double at the trust boundary before Kafka sees them.
When it happens
Trigger: Constructing a client or calling ConfigDef.validate with a DOUBLE-typed config key set to a Boolean, List, Map, Class, or a custom object that is not a java.lang.Number and not a String.
Common situations: A config framework that returns typed objects (e.g. HOCON returning a Boolean for an unquoted true/false) feeding a DOUBLE key; YAML aliases resolving to nested maps; programmatic configs that mistakenly put a comma-separated list into a numeric key; copy-paste of a value from a STRING-typed setting into a DOUBLE-typed one.
Related errors
- Expected value to be a 64-bit integer (long), but it was a v
- Expected a comma separated list.
- Expected a Class instance or class name.
- Invalid url in bootstrap.servers: {url}
- Not a number of type type
AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03).
Data as JSON: /data/errors/b5654fa79b5ba116.json.
Report an issue: GitHub.