{"record":{"id":"27a4348e29cb24e1","repo":"apache/kafka","slug":"invalid-port-in-bootstrap-servers","errorCode":null,"errorMessage":"Invalid port in bootstrap.servers: {}","messagePattern":"Invalid port in bootstrap\\.servers: (.+?)","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/BootstrapConfiguration.java","lineNumber":52,"sourceCode":"                                   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":34,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/BootstrapConfiguration.java#L34-L58","documentation":"ConfigException thrown by BootstrapConfiguration.enabled when Utils.getPort(url) raises IllegalArgumentException during parsing — i.e. the port segment is present but not a valid integer. Distinct from 'Invalid url' (which fires when port is null); this fires when the port token cannot be parsed as a number.","triggerScenarios":"The inner try at line 49-51 calls getPort(url); if it throws IllegalArgumentException (caught at line 53), the message becomes 'Invalid port in bootstrap.servers: <url>'. Triggered by entries like 'host:abc', 'host:999999999' (out of range), or 'host:-1'.","commonSituations":"Typing a non-numeric port ('host:kafka'); pasting a port with a unicode lookalike digit; out-of-range port (>65535); negative port from a templating bug.","solutions":["Use a numeric port in the valid range 0-65535, conventionally 9092 for Kafka.","Check for hidden/non-ASCII digits in the config (e.g. from copy-paste).","Validate each entry programmatically before constructing the client (see validationCode).","If templating the port, ensure the variable resolves to an integer literal."],"exampleFix":"// before\nbootstrap.servers=broker1:9o92\n// after\nbootstrap.servers=broker1:9092","handlingStrategy":"validation","validationCode":"// Pre-validate the port parses as an int in range\nfor (String url : bootstrapServers) {\n  String[] parts = url.split(\":\");\n  if (parts.length == 2) {\n    int p = Integer.parseInt(parts[1]); // NumberFormatException surfaces the bad token\n    if (p < 0 || p > 65535) throw new IllegalArgumentException(\"port out of range: \" + url);\n  }\n}","typeGuard":null,"tryCatchPattern":"try { BootstrapConfiguration.enabled(urls, dns, t, backoff); } catch (ConfigException e) { if (e.message.contains('Invalid port in bootstrap')) { /* fix the port token */ } else throw e; }","preventionTips":["Use numeric ports in 0-65535.","Beware non-ASCII digit lookalikes from copy-paste.","Template ports as integers, not free text."],"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"}