{"record":{"id":"067206f0a8f96a57","repo":"apache/kafka","slug":"invalid-port-in-bootstrap-servers-067206","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/ClientUtils.java","lineNumber":134,"sourceCode":"\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     *\n     * @param config client configs\n     * @param time the time implementation\n     * @param logContext the logging context\n     *\n     * @return configured ChannelBuilder based on the configs.","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java#L116-L152","documentation":"ConfigException from ClientUtils.parseAndValidateAddresses when Utils.getPort(url) throws IllegalArgumentException — the port token is not a valid integer. Same shape as BootstrapConfiguration error 12 but raised during address resolution.","triggerScenarios":"getPort(url) at line 131 throws IllegalArgumentException, caught at line 134, rethrown as ConfigException(\"Invalid port in bootstrap.servers: <url>\"). Triggered by non-numeric, out-of-range, or negative port segments.","commonSituations":"Non-numeric port from a misconfigured environment variable; out-of-range port; copy-paste introducing a non-digit character.","solutions":["Use a numeric port in 0-65535 (typically 9092).","Sanitize templated ports to integers.","Pre-validate the list with a regex like ^(\\w[\\w.-]*):(\\d{1,5})$ before calling.","Inspect the offending url in the exception message."],"exampleFix":"// before\nList<String> urls = List.of(\"broker1:abc\");\n// after\nList<String> urls = List.of(\"broker1:9092\");","handlingStrategy":"validation","validationCode":"for (String url : urls) {\n  Integer port = null;\n  try { port = Utils.getPort(url); } catch (IllegalArgumentException ignore) {}\n  if (port == null || port < 0 || port > 65535)\n    throw new IllegalArgumentException(\"Bad port in \" + url);\n}","typeGuard":null,"tryCatchPattern":"try { ClientUtils.parseAndValidateAddresses(urls, dns); } catch (ConfigException e) { if (e.message.contains('Invalid port in bootstrap')) { /* fix port token */ } else throw e; }","preventionTips":["Pre-validate ports as integers in range.","Sanitize templated port values.","Watch for hidden non-digit characters."],"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"}