{"id":"e426fbbd84e54a61","repo":"apache/kafka","slug":"invalid-url-in-bootstrap-servers-url-e426fb","errorCode":null,"errorMessage":"Invalid url in bootstrap.servers: {url}","messagePattern":"Invalid url in bootstrap\\.servers: (.+?)","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/ClientUtils.java","lineNumber":135,"sourceCode":"    public static List<InetSocketAddress> parseAndValidateAddresses(AbstractConfig config) {\n        List<String> urls = config.getList(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);\n        String clientDnsLookupConfig = config.getString(CommonClientConfigs.CLIENT_DNS_LOOKUP_CONFIG);\n        return parseAndValidateAddresses(urls, clientDnsLookupConfig);\n    }\n\n    public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls, String clientDnsLookupConfig) {\n        return parseAndValidateAddresses(urls, ClientDnsLookup.forConfig(clientDnsLookupConfig));\n    }\n\n    public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls, ClientDnsLookup clientDnsLookup) {\n        List<InetSocketAddress> addresses = new ArrayList<>();\n        for (String url : urls) {\n            if (url != null && !url.isEmpty()) {\n                try {\n                    String host = getHost(url);\n                    Integer port = getPort(url);\n                    if (host == null || port == null)\n                        throw new ConfigException(\"Invalid url in \" + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + \": \" + url);\n\n                    addresses.addAll(resolveAddress(url, host, port, clientDnsLookup));\n\n                } catch (IllegalArgumentException e) {\n                    throw new ConfigException(\"Invalid port in \" + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + \": \" + url);\n                } catch (UnknownHostException e) {\n                    throw new ConfigException(\"Unknown host in \" + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + \": \" + url);\n                }\n            }\n        }\n        if (addresses.isEmpty())\n            throw new ConfigException(\"No resolvable bootstrap urls given in \" + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);\n        return addresses;\n    }\n\n    /**\n     * Create a new channel builder from the provided configuration.\n     *","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java#L117-L153","documentation":"ConfigException thrown inside ClientUtils.parseAndValidateAddresses when Utils.getHost or Utils.getPort returns null for a non-empty bootstrap entry, meaning the entry cannot be split into a host and a numeric port. This is the canonical producer/consumer/admin bootstrap validation path and runs whenever a client resolves its initial broker list.","triggerScenarios":"Passing bootstrap.servers containing an entry without a port ('brokerA'), without a host (':9092'), or with a non-numeric port token. Reached from any client constructor that calls parseAndValidateAddresses, including KafkaProducer, KafkaConsumer, AdminClient, KafkaStreams, and Connect workers.","commonSituations":"Typo in a properties file, a ${BROKER_URL} placeholder that resolves without a port, copy-pasting a URL with a scheme ('kafka://host'), or mixing whitespace separators where a comma is required.","solutions":["Read the offending 'url' token in the message and confirm the expected 'host:port' shape.","Fix the specific bootstrap.servers entry so host and numeric port are both present.","Confirm the entry is comma-separated from neighbours and contains no scheme prefix or surrounding whitespace."],"exampleFix":"// before\nbootstrap.servers=kafka-broker\n// after\nbootstrap.servers=kafka-broker:9092","handlingStrategy":"validation","validationCode":"// Same root cause as [11] — ClientUtils.parseAndValidateAddresses throws\n// ConfigException when getHost(url) or getPort(url) returns null.\n// Pre-validate with the exact helpers the library itself uses:\nimport org.apache.kafka.common.utils.Utils;\n\nstatic List<String> sanitizeBootstrap(List<String> raw) {\n    List<String> ok = new ArrayList<>();\n    for (String url : raw) {\n        if (url == null || url.isBlank()) continue;\n        if (Utils.getHost(url) == null || Utils.getPort(url) == null)\n            throw new IllegalArgumentException(\"Invalid bootstrap url: \" + url);\n        ok.add(url);\n    }\n    if (ok.isEmpty()) throw new IllegalArgumentException(\"No valid bootstrap urls supplied\");\n    return ok;\n}\n// props.put(BOOTSTRAP_SERVERS_CONFIG, sanitizeBootstrap(rawList));","typeGuard":"static boolean isParsableBootstrapUrl(String url) {\n    return url != null && !url.isBlank()\n        && Utils.getHost(url) != null\n        && Utils.getPort(url) != null;\n}","tryCatchPattern":"try {\n    producer = new KafkaProducer<>(props);\n} catch (ConfigException e) {\n    if (e.getMessage().startsWith(\"Invalid url in bootstrap.servers\")) {\n        // config is wrong; recreating with the same props will fail identically.\n        throw new ConfigurationException(\"Fix bootstrap.servers: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Treat bootstrap.servers as structured data (host + port), not a free-form string; validate at the config-loading boundary.","Log the exact value that fails — masking or redaction is rarely needed for host:port, and the literal string is what operators need to debug.","Reject empty/null entries in the comma-separated list before they reach Kafka.","Run the validation in a startup health-check so the service fails fast at boot rather than on first request."],"tags":["config","bootstrap-servers","validation","client"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}