{"id":"b5654fa79b5ba116","repo":"apache/kafka","slug":"expected-value-to-be-a-double-but-it-was-a-value","errorCode":null,"errorMessage":"Expected value to be a double, but it was a value.getClass().getName()","messagePattern":"Expected value to be a double, 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":767,"sourceCode":"                    } 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:\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:","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L749-L785","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nprops.put(\"my.ratio\", true); // Boolean -> ConfigException\n\n// after\nprops.put(\"my.ratio\", 0.5);  // Double\nprops.put(\"my.ratio\", \"0.5\");","handlingStrategy":"type-guard","validationCode":"Object v = rawValue;\nif (!(v instanceof Number) && !(v instanceof String)) {\n    throw new IllegalArgumentException(\"config '\" + key + \"' must be a Number or numeric string\");\n}\nif (v instanceof String) {\n    Double.parseDouble(((String) v).trim());\n}","typeGuard":"public static boolean isDoubleValue(Object v) {\n    if (v instanceof Number) return true;\n    if (v instanceof String) {\n        try { Double.parseDouble(((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 double\")) {\n        // coerce the value to a Number and retry\n    } else throw e;\n}","preventionTips":["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."],"tags":["config","type-mismatch","client"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}