{"id":"9e7eddc4fccb79f9","repo":"apache/kafka","slug":"invalid-port-in-bootstrap-servers-url","errorCode":null,"errorMessage":"Invalid port in bootstrap.servers: {url}","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":140,"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":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/ClientUtils.java#L122-L158","documentation":"ConfigException thrown when the port token of a bootstrap entry cannot be parsed as an integer — Integer.parseInt raises IllegalArgumentException inside the port extraction, which ClientUtils.parseAndValidateAddresses catches and re-wraps as this ConfigException. It indicates the host was present but the port was malformed (non-numeric or out of integer range).","triggerScenarios":"A bootstrap entry such as 'host:ninety-two', 'host:99999999999', or 'host:' where the port substring is not a valid int. Triggered by the same client constructors that exercise parseAndValidateAddresses.","commonSituations":"Using a service-name placeholder that leaks a non-numeric value, copy-pasting an HTTPS-style port like 'host:https', or a YAML/env interpolation that injects a labelled value ('9092/tcp').","solutions":["Check the 'url' in the message and replace the port token with a decimal integer in [0,65535].","If the port comes from an env var, ensure the variable holds digits only (no protocol suffix, no quotes).","Re-run the client after correcting bootstrap.servers; no restart of the broker is needed."],"exampleFix":"// before\nbootstrap.servers=broker1:NINETY_TWO\n// after\nbootstrap.servers=broker1:9092","handlingStrategy":"validation","validationCode":"// The port portion fails Integer.parse (non-numeric, out of range, or missing).\n// Validate explicitly with the legal TCP range:\nstatic void checkPorts(List<String> servers) {\n    for (String url : servers) {\n        Integer port = Utils.getPort(url);          // null if unparsable\n        if (port == null || port < 1 || port > 65535)\n            throw new IllegalArgumentException(\n                \"Invalid port in bootstrap.servers: \" + url);\n    }\n}","typeGuard":"static boolean hasValidPort(String url) {\n    Integer p = Utils.getPort(url);\n    return p != null && p >= 1 && p <= 65535;\n}","tryCatchPattern":"try {\n    consumer = new KafkaConsumer<>(props);\n} catch (ConfigException e) {\n    if (e.getMessage().startsWith(\"Invalid port in bootstrap.servers\")) {\n        // e.g. \"localhost:notANumber\" or \"localhost:99999\"\n        alertOps(\"Malformed port in bootstrap.servers: \" + e.getMessage());\n        throw e;            // unrecoverable with current config\n    }\n    throw e;\n}","preventionTips":["Use the canonical Kafka port 9092 unless you have an explicit reason not to; resist templating the port from untrusted input.","Coerce ports through Integer.parseInt with a 1..65535 range check at the config boundary — never pass a raw String straight through.","Beware IPv6 literals: enclose the host in brackets, e.g. [2001:db8::1]:9092, otherwise the port parser will mis-split.","Add a config-lint step in deployment that rejects any bootstrap url whose port substring is non-numeric."],"tags":["config","bootstrap-servers","port","validation"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}