apache/kafka · error · ConfigException

Invalid url in bootstrap.servers: {}

Error message

Invalid url in bootstrap.servers: {}

What it means

ConfigException from ClientUtils.parseAndValidateAddresses when, for a non-empty url, Utils.getHost(url) or Utils.getPort(url) returns null — the URL is missing host or port. This is the same validation as BootstrapConfiguration but applied at address-resolution time, where the addresses list is built for the NetworkClient.

Source

Thrown at clients/src/main/java/org/apache/kafka/clients/ClientUtils.java:129

                // Silently ignore - this matches the original behavior
            }
        }
        return addresses;
    }

    public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls, String clientDnsLookupConfig) {
        return parseAndValidateAddresses(urls, ClientDnsLookup.forConfig(clientDnsLookupConfig));
    }

    public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls, ClientDnsLookup clientDnsLookup) {
        List<InetSocketAddress> addresses = new ArrayList<>();
        for (String url : urls) {
            if (url != null && !url.isEmpty()) {
                try {
                    String host = getHost(url);
                    Integer port = getPort(url);
                    if (host == null || port == null)
                        throw new ConfigException("Invalid url in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);

                    addresses.addAll(resolveAddress(url, host, port, clientDnsLookup));

                } catch (IllegalArgumentException e) {
                    throw new ConfigException("Invalid port in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
                } catch (UnknownHostException e) {
                    throw new ConfigException("Unknown host in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
                }
            }
        }
        if (addresses.isEmpty())
            throw new ConfigException("No resolvable bootstrap urls given in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);
        return addresses;
    }

    /**
     * Create a new channel builder from the provided configuration.
     *

View on GitHub (pinned to 996fb4585a)

Solutions

  1. Ensure every entry is host:port.
  2. Filter empty/null entries before calling (the method skips null/empty but not malformed).
  3. Validate upstream: use BootstrapConfiguration.enabled first for a consistent error, or pre-check with Utils.getHost/getPort.
  4. Log the offending url from the exception to locate the bad entry.

Example fix

// before
List<String> urls = List.of("broker1");
ClientUtils.parseAndValidateAddresses(urls, dns);
// after
List<String> urls = List.of("broker1:9092");
ClientUtils.parseAndValidateAddresses(urls, dns);
Defensive patterns

Strategy: validation

Validate before calling

List<String> clean = urls.stream().filter(u -> u != null && !u.isEmpty() && Utils.getHost(u) != null && Utils.getPort(u) != null).toList();
if (clean.size() != urls.stream().filter(u -> u != null && !u.isEmpty()).count())
  throw new IllegalArgumentException("Some bootstrap urls are missing host or port");

Try / catch

try { ClientUtils.parseAndValidateAddresses(urls, dns); } catch (ConfigException e) { if (e.message.contains('Invalid url in bootstrap')) { /* fix host:port */ } else throw e; }

Prevention

When it happens

Trigger: Line 132: if host==null || port==null inside the loop over urls, throw ConfigException("Invalid url in bootstrap.servers: <url>"). Triggered by malformed entries (no host or no port) passed directly to parseAndValidateAddresses.

Common situations: Calling ClientUtils.parseAndValidateAddresses with a hand-built list that omits the port; config supplied via environment variable that lost the port; bootstrap.servers with a stray comma or scheme-only token.

Related errors


AI-assisted analysis of apache/kafka@996fb4585a (2026-08-11). Data as JSON: /api/errors/ba42d5bd3ff279b9. Report an issue: GitHub.