apache/kafka · error · ConfigException

Not a number of type type

Error message

Not a number of type type

What it means

Catch block in ConfigDef.parseType that wraps a NumberFormatException raised by Integer.parseInt, Short.parseShort, Long.parseLong, or Double.parseDouble when the input string is not a well-formed number for the declared type. The message reports the declared Type (INT/SHORT/LONG/DOUBLE) so the developer knows which parser failed. This is the canonical 'bad numeric literal' failure for numeric Kafka configs.

Source

Thrown at clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java:789

                    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:
                    throw new IllegalStateException("Unknown type.");
            }
        } catch (NumberFormatException e) {
            throw new ConfigException(name, value, "Not a number of type " + type);
        } catch (ClassNotFoundException e) {
            throw new ConfigException(name, value, "Class " + value + " could not be found.");
        }
    }

    /**
     * Convert the provided object into a string based on its type.
     * <p>
     * This method uses Java's {@link #toString()} for {@link Type#BOOLEAN}, {@link Type#SHORT}, {@link Type#INT},
     * {@link Type#LONG}, {@link Type#DOUBLE}, {@link Type#STRING} and {@link Type#PASSWORD} objects.
     * For {@link Type#LIST} objects, Java's {@link #toString()} is used for each entry and entries are concatenated
     * separated by commas. For {@link Type#CLASS} objects, {@link Class#getName()} is used.
     * @param parsedValue The object to convert into a string
     * @param type The type of the object
     * @return The string representation of the provided object and type
     */
    public static String convertToString(Object parsedValue, Type type) {
        if (parsedValue == null) {

View on GitHub (pinned to c31c9215e1)

Solutions

  1. Strip any unit suffix and grouping characters: write "1024" not "1,024", "5000" not "5000ms".
  2. Confirm the declared Type for the key — a value like "5.0" only works for DOUBLE, not for INT/LONG.
  3. Trim whitespace and verify there is no hidden non-ASCII character in the property source.
  4. If loading from external config, validate with Long.parseLong/Double.parseDouble before passing to Kafka to surface the failure with a clearer trace.

Example fix

// before
props.put(ProducerConfig.RECONNECT_BACKOFF_MS_CONFIG, "5000ms");
// -> ConfigException: Not a number of type LONG

// after
props.put(ProducerConfig.RECONNECT_BACKOFF_MS_CONFIG, "5000");
Defensive patterns

Strategy: validation

Validate before calling

if (value instanceof String) {
    String s = ((String) value).trim();
    switch (type) {
        case INT:    Integer.parseInt(s);  break;
        case SHORT:  Short.parseShort(s); break;
        case LONG:   Long.parseLong(s);   break;
        case DOUBLE: Double.parseDouble(s); break;
    }
}

Type guard

public static boolean parsesAsNumber(String s, ConfigDef.Type type) {
    try {
        switch (type) {
            case INT:    Integer.parseInt(s);  return true;
            case SHORT:  Short.parseShort(s); return true;
            case LONG:   Long.parseLong(s);   return true;
            case DOUBLE: Double.parseDouble(s); return true;
        }
    } catch (NumberFormatException e) { return false; }
    return false;
}

Try / catch

try {
    configDef.parse(configs);
} catch (ConfigException e) {
    if (e.getMessage().startsWith("Not a number of type")) {
        // prompt for a corrected numeric string or substitute a default
    } else throw e;
}

Prevention

When it happens

Trigger: Passing a numeric-typed config (INT/SHORT/LONG/DOUBLE) as a String that cannot be parsed by the matching JDK parse method — e.g. retries="abc", fetch.min.bytes="1,024" (comma grouping), max.in.flight.requests.per.connection="5.0" for an INT key, or a trailing unit like "5000ms" on a LONG key.

Common situations: Env vars or YAML values with locale-specific decimal separators; values copied from docs that include units ("30s", "10MB"); trailing whitespace or hidden BOM characters in property files; Spring placeholder resolution producing an empty string; users assuming Kafka honors duration suffixes like DurationStyle ISO-8601 when the key is plain ms.

Related errors


AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03). Data as JSON: /data/errors/7d23196ad3129834.json. Report an issue: GitHub.