{"id":"7d23196ad3129834","repo":"apache/kafka","slug":"not-a-number-of-type-type","errorCode":null,"errorMessage":"Not a number of type type","messagePattern":"Not a number of type type","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java","lineNumber":789,"sourceCode":"                    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:\n                    if (value instanceof Class)\n                        return value;\n                    else if (value instanceof String) {\n                        return Utils.loadClass(trimmed, Object.class);\n                    } else\n                        throw new ConfigException(name, value, \"Expected a Class instance or class name.\");\n                default:\n                    throw new IllegalStateException(\"Unknown type.\");\n            }\n        } catch (NumberFormatException e) {\n            throw new ConfigException(name, value, \"Not a number of type \" + type);\n        } catch (ClassNotFoundException e) {\n            throw new ConfigException(name, value, \"Class \" + value + \" could not be found.\");\n        }\n    }\n\n    /**\n     * Convert the provided object into a string based on its type.\n     * <p>\n     * This method uses Java's {@link #toString()} for {@link Type#BOOLEAN}, {@link Type#SHORT}, {@link Type#INT},\n     * {@link Type#LONG}, {@link Type#DOUBLE}, {@link Type#STRING} and {@link Type#PASSWORD} objects.\n     * For {@link Type#LIST} objects, Java's {@link #toString()} is used for each entry and entries are concatenated\n     * separated by commas. For {@link Type#CLASS} objects, {@link Class#getName()} is used.\n     * @param parsedValue The object to convert into a string\n     * @param type The type of the object\n     * @return The string representation of the provided object and type\n     */\n    public static String convertToString(Object parsedValue, Type type) {\n        if (parsedValue == null) {","sourceCodeStart":771,"sourceCodeEnd":807,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L771-L807","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Strip any unit suffix and grouping characters: write \"1024\" not \"1,024\", \"5000\" not \"5000ms\".","Confirm the declared Type for the key — a value like \"5.0\" only works for DOUBLE, not for INT/LONG.","Trim whitespace and verify there is no hidden non-ASCII character in the property source.","If loading from external config, validate with Long.parseLong/Double.parseDouble before passing to Kafka to surface the failure with a clearer trace."],"exampleFix":"// before\nprops.put(ProducerConfig.RECONNECT_BACKOFF_MS_CONFIG, \"5000ms\");\n// -> ConfigException: Not a number of type LONG\n\n// after\nprops.put(ProducerConfig.RECONNECT_BACKOFF_MS_CONFIG, \"5000\");","handlingStrategy":"validation","validationCode":"if (value instanceof String) {\n    String s = ((String) value).trim();\n    switch (type) {\n        case INT:    Integer.parseInt(s);  break;\n        case SHORT:  Short.parseShort(s); break;\n        case LONG:   Long.parseLong(s);   break;\n        case DOUBLE: Double.parseDouble(s); break;\n    }\n}","typeGuard":"public static boolean parsesAsNumber(String s, ConfigDef.Type type) {\n    try {\n        switch (type) {\n            case INT:    Integer.parseInt(s);  return true;\n            case SHORT:  Short.parseShort(s); return true;\n            case LONG:   Long.parseLong(s);   return true;\n            case DOUBLE: Double.parseDouble(s); return true;\n        }\n    } catch (NumberFormatException e) { return false; }\n    return false;\n}","tryCatchPattern":"try {\n    configDef.parse(configs);\n} catch (ConfigException e) {\n    if (e.getMessage().startsWith(\"Not a number of type\")) {\n        // prompt for a corrected numeric string or substitute a default\n    } else throw e;\n}","preventionTips":["Reject numeric config strings containing whitespace, units, or locale-specific decimals.","Document the expected numeric type per key in your config schema."],"tags":["config","number-format","parsing","client"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}