{"record":{"id":"717e60509484a055","repo":"apache/kafka","slug":"invalid-url-in-bootstrap-servers","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/BootstrapConfiguration.java","lineNumber":50,"sourceCode":"\n    private BootstrapConfiguration(final List<String> bootstrapServers,\n                                   final ClientDnsLookup clientDnsLookup,\n                                   final long bootstrapResolveTimeoutMs,\n                                   final long retryBackoffMs) {\n        this.bootstrapServers = bootstrapServers;\n        this.clientDnsLookup = clientDnsLookup;\n        this.bootstrapResolveTimeoutMs = bootstrapResolveTimeoutMs;\n        this.retryBackoffMs = retryBackoffMs;\n    }\n\n    public static BootstrapConfiguration enabled(final List<String> bootstrapServers,\n                                                 final ClientDnsLookup clientDnsLookup,\n                                                 final long bootstrapResolveTimeoutMs,\n                                                 final long retryBackoffMs) {\n        for (String url : bootstrapServers) {\n            try {\n                if (Utils.getHost(url) == null || Utils.getPort(url) == null)\n                    throw new ConfigException(\"Invalid url in \" + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + \": \" + url);\n            } catch (IllegalArgumentException e) {\n                throw new ConfigException(\"Invalid port in \" + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + \": \" + url);\n            }\n        }\n        return new BootstrapConfiguration(bootstrapServers, clientDnsLookup, bootstrapResolveTimeoutMs, retryBackoffMs);\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/BootstrapConfiguration.java#L32-L58","documentation":"ConfigException thrown by BootstrapConfiguration.enabled when, for a given bootstrap.servers entry, Utils.getHost(url) or Utils.getPort(url) returns null — i.e. the URL is malformed in a way that no host or port can be parsed. This is a fail-fast validation of the bootstrap.servers list before any network activity.","triggerScenarios":"Inside the for loop at line 47, if host==null || port==null then throw ConfigException(\"Invalid url in bootstrap.servers: <url>\"). Triggered by entries like 'localhost' (no port), ':9092' (no host), 'kafka://' (scheme only), or empty fragments.","commonSituations":"Passing 'localhost' instead of 'localhost:9092'; using a URL with a scheme but no host/port; trailing commas producing empty entries; copy-paste from docs that omit the port.","solutions":["Provide each broker as host:port, e.g. 'localhost:9092'.","Remove scheme prefixes unless required ('kafka://host:9092' — prefer bare 'host:9092').","Sanitize the list before passing it: trim and drop blank/null entries.","If you need URLs with schemes, confirm Utils.getHost/Utils.getPort accept that form for your client version."],"exampleFix":"// before\nbootstrap.servers=localhost\n// after\nbootstrap.servers=localhost:9092","handlingStrategy":"validation","validationCode":"// Validate each bootstrap entry before constructing the client\nfor (String url : bootstrapServers) {\n  if (url == null || url.isEmpty()) continue;\n  if (Utils.getHost(url) == null || Utils.getPort(url) == null)\n    throw new IllegalArgumentException(\"Bad bootstrap url (need host:port): \" + url);\n}","typeGuard":null,"tryCatchPattern":"try { BootstrapConfiguration.enabled(urls, dns, t, backoff); } catch (ConfigException e) { if (e.message.contains('Invalid url in bootstrap')) { /* fix bootstrap.servers */ } else throw e; }","preventionTips":["Always specify host:port for every broker.","Strip blank entries and trailing commas from the list.","Avoid URL schemes unless your client version parses them."],"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"}