{"record":{"id":"ba42d5bd3ff279b9","repo":"apache/kafka","slug":"invalid-url-in-bootstrap-servers-ba42d5","errorCode":null,"errorMessage":"Invalid url in bootstrap.servers: {}","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":129,"sourceCode":"                // Silently ignore - this matches the original behavior\n            }\n        }\n        return addresses;\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":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java#L111-L147","documentation":"ConfigException from ClientUtils.parseAndValidateAddresses when, for a non-empty url, Utils.getHost(url) or Utils.getPort(url) returns null — the URL is missing host or port. This is the same validation as BootstrapConfiguration but applied at address-resolution time, where the addresses list is built for the NetworkClient.","triggerScenarios":"Line 132: if host==null || port==null inside the loop over urls, throw ConfigException(\"Invalid url in bootstrap.servers: <url>\"). Triggered by malformed entries (no host or no port) passed directly to parseAndValidateAddresses.","commonSituations":"Calling ClientUtils.parseAndValidateAddresses with a hand-built list that omits the port; config supplied via environment variable that lost the port; bootstrap.servers with a stray comma or scheme-only token.","solutions":["Ensure every entry is host:port.","Filter empty/null entries before calling (the method skips null/empty but not malformed).","Validate upstream: use BootstrapConfiguration.enabled first for a consistent error, or pre-check with Utils.getHost/getPort.","Log the offending url from the exception to locate the bad entry."],"exampleFix":"// before\nList<String> urls = List.of(\"broker1\");\nClientUtils.parseAndValidateAddresses(urls, dns);\n// after\nList<String> urls = List.of(\"broker1:9092\");\nClientUtils.parseAndValidateAddresses(urls, dns);","handlingStrategy":"validation","validationCode":"List<String> clean = urls.stream().filter(u -> u != null && !u.isEmpty() && Utils.getHost(u) != null && Utils.getPort(u) != null).toList();\nif (clean.size() != urls.stream().filter(u -> u != null && !u.isEmpty()).count())\n  throw new IllegalArgumentException(\"Some bootstrap urls are missing host or port\");","typeGuard":null,"tryCatchPattern":"try { ClientUtils.parseAndValidateAddresses(urls, dns); } catch (ConfigException e) { if (e.message.contains('Invalid url in bootstrap')) { /* fix host:port */ } else throw e; }","preventionTips":["Build the url list with explicit host:port literals.","Validate with Utils.getHost/getPort before calling parseAndValidateAddresses.","Log the offending url from the exception."],"tags":["kafka-client","config","bootstrap","network"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}