{"id":"fa86670bd2077c1d","repo":"apache/kafka","slug":"expected-a-comma-separated-list","errorCode":null,"errorMessage":"Expected a comma separated list.","messagePattern":"Expected a comma separated list\\.","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java","lineNumber":777,"sourceCode":"                    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:\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    /**","sourceCodeStart":759,"sourceCodeEnd":795,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L759-L795","documentation":"Thrown by the Type.LIST branch of ConfigDef.parseType when the value is neither a java.util.List nor a String. LIST-typed configs (e.g. bootstrap.servers is LIST<STRING>, client.dns.lookup, config.providers, metric.reporters) are accepted either as a ready-made List or as a comma-separated String that gets split on comma-with-whitespace. Any other runtime type (Number, Boolean, Map, Object[]) is rejected.","triggerScenarios":"Calling ConfigDef.parse/validate (transitively, any Kafka client constructor) with a LIST-typed config set to a non-List, non-String object — e.g. a String[] array, a Set, a Map, or a single Number where a list was expected.","commonSituations":"Spring/Typesafe Config returning a String[] or ConfigObject instead of List<String>; passing a java.util.Set where List is expected; a property placeholder that resolved to null and was then substituted with a default of the wrong type; building bootstrap.servers from a single String in code that happens to be a non-String object after templating.","solutions":["Pass a comma-separated String (e.g. bootstrap.servers=\"k1:9092,k2:9092\").","Or pass a java.util.List<String> built with List.of(...) or Arrays.asList(...).","If a config framework yields String[] or Set, convert with new ArrayList<>(Arrays.asList(arr)) or new ArrayList<>(set) before handing the value to Kafka.","For empty list, pass an empty String or List.of(); avoid null unless the key is documented as nullable."],"exampleFix":"// before\nprops.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,\n         new String[]{\"k1:9092\",\"k2:9092\"}); // array -> ConfigException\n\n// after\nprops.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,\n         Arrays.asList(\"k1:9092\",\"k2:9092\"));\n// or\nprops.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, \"k1:9092,k2:9092\");","handlingStrategy":"type-guard","validationCode":"Object v = rawValue;\nif (!(v instanceof List) && !(v instanceof String)) {\n    throw new IllegalArgumentException(\"config '\" + key + \"' must be a List or comma-separated string\");\n}","typeGuard":"public static boolean isListValue(Object v) {\n    return v instanceof List || v instanceof String;\n}","tryCatchPattern":"try {\n    configDef.parse(configs);\n} catch (ConfigException e) {\n    if (e.getMessage().contains(\"Expected a comma separated list\")) {\n        // wrap or coerce value to a String/List and retry\n    } else throw e;\n}","preventionTips":["For LIST config, always supply either List<Object> or a plain comma-delimited String.","Avoid passing arrays, sets, or custom collections; convert to List first."],"tags":["config","type-mismatch","client","bootstrap-servers"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}