{"id":"6e72102fe5652d05","repo":"apache/kafka","slug":"invalid-url-in-bootstrap-servers-url","errorCode":null,"errorMessage":"Invalid url in bootstrap.servers: {url}","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":49,"sourceCode":"    public final long retryBackoffMs;\n\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            if (Utils.getHost(url) == null || Utils.getPort(url) == null)\n                throw new ConfigException(\"Invalid url in \" + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + \": \" + url);\n        }\n        return new BootstrapConfiguration(bootstrapServers, clientDnsLookup, bootstrapResolveTimeoutMs, retryBackoffMs);\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":54,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/BootstrapConfiguration.java#L31-L54","documentation":"ConfigException thrown by BootstrapConfiguration.enabled() when one of the supplied bootstrap URLs fails to yield both a host and a port via Utils.getHost/Utils.getPort. This is the lightweight pre-flight validation invoked from ClientUtils.createNetworkClient before any DNS resolution or NetworkClient construction, so malformed bootstrap strings abort client creation early.","triggerScenarios":"Constructing a KafkaProducer/KafkaConsumer/AdminClient/KafkaClient whose bootstrap.servers config contains an entry like 'kafka' (no port), ':9092' (no host), 'localhost:notaport' (non-numeric), or an empty string. Reached via BootstrapConfiguration.enabled(...) inside createNetworkClient.","commonSituations":"Loading bootstrap.servers from an environment variable or properties file that drops the port, copying a broker URL formatted for a schema registry ('http://host:8081'), IPv6 literals without brackets, or trailing commas that create blank entries.","solutions":["Inspect the exact 'url' value printed in the message; every bootstrap entry must be 'host:port' with a 1-65535 numeric port.","Correct the bootstrap.servers value, e.g. 'localhost:9092,kafka2:9092'. For IPv6 use '[::1]:9092'.","Validate the config source (env var / Properties file / Spring placeholder) is not stripping the port or injecting an extra scheme prefix."],"exampleFix":"// before\nprops.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, \"kafka1 kafka2:9092\");\n// after\nprops.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, \"kafka1:9092,kafka2:9092\");","handlingStrategy":"validation","validationCode":"// Validate every bootstrap.servers entry BEFORE constructing the client.\n// Kafka wants the form host:port (no scheme, no path).\nimport org.apache.kafka.common.utils.Utils;\n\nstatic void checkBootstrapServers(List<String> servers) {\n    if (servers == null || servers.isEmpty())\n        throw new IllegalArgumentException(\"bootstrap.servers is empty\");\n    for (String url : servers) {\n        String host = Utils.getHost(url);\n        Integer port = Utils.getPort(url);\n        if (host == null || port == null)\n            throw new IllegalArgumentException(\"Invalid bootstrap url (expect host:port): \" + url);\n    }\n}\n\n// Call this with the same list you will pass as CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG.","typeGuard":"// Predicate the caller can use to filter/guard before config construction.\nstatic boolean isValidBootstrapUrl(String url) {\n    return url != null\n        && Utils.getHost(url) != null\n        && Utils.getPort(url) != null;\n}\n\n// List<String> clean = raw.stream().filter(App::isValidBootstrapUrl).toList();","tryCatchPattern":"// Wrap client construction; ConfigException is the failure type.\ntry {\n    try (var admin = AdminClient.create(props)) {\n        // ... use admin ...\n    }\n} catch (org.apache.kafka.common.config.ConfigException e) {\n    if (e.getMessage().contains(\"bootstrap.servers\")) {\n        log.error(\"Bad bootstrap.servers config: {}\", e.getMessage());\n        // surface to operator / fail fast — do NOT retry with the same value.\n    } else throw e;\n}","preventionTips":["Source bootstrap.servers from a single validated config object rather than concatenating strings in multiple places.","Reject URLs containing schemes (kafka://), paths, or query strings at config-load time — Kafka accepts only host:port pairs.","Provide at least 2–3 bootstrap servers so that one malformed or unreachable entry does not sink the whole client.","Unit-test the config parser with property/fuzz inputs before deploying."],"tags":["config","bootstrap-servers","validation"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}