apache/kafka · error · ConfigException

Invalid url in bootstrap.servers: {}

Error message

Invalid url in bootstrap.servers: {}

What it means

ConfigException thrown by BootstrapConfiguration.enabled when, for a given bootstrap.servers entry, Utils.getHost(url) or Utils.getPort(url) returns null — i.e. the URL is malformed in a way that no host or port can be parsed. This is a fail-fast validation of the bootstrap.servers list before any network activity.

Source

Thrown at clients/src/main/java/org/apache/kafka/clients/BootstrapConfiguration.java:50

    private BootstrapConfiguration(final List<String> bootstrapServers,
                                   final ClientDnsLookup clientDnsLookup,
                                   final long bootstrapResolveTimeoutMs,
                                   final long retryBackoffMs) {
        this.bootstrapServers = bootstrapServers;
        this.clientDnsLookup = clientDnsLookup;
        this.bootstrapResolveTimeoutMs = bootstrapResolveTimeoutMs;
        this.retryBackoffMs = retryBackoffMs;
    }

    public static BootstrapConfiguration enabled(final List<String> bootstrapServers,
                                                 final ClientDnsLookup clientDnsLookup,
                                                 final long bootstrapResolveTimeoutMs,
                                                 final long retryBackoffMs) {
        for (String url : bootstrapServers) {
            try {
                if (Utils.getHost(url) == null || Utils.getPort(url) == null)
                    throw new ConfigException("Invalid url in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
            } catch (IllegalArgumentException e) {
                throw new ConfigException("Invalid port in " + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG + ": " + url);
            }
        }
        return new BootstrapConfiguration(bootstrapServers, clientDnsLookup, bootstrapResolveTimeoutMs, retryBackoffMs);
    }
}

View on GitHub (pinned to 996fb4585a)

Solutions

  1. Provide each broker as host:port, e.g. 'localhost:9092'.
  2. Remove scheme prefixes unless required ('kafka://host:9092' — prefer bare 'host:9092').
  3. Sanitize the list before passing it: trim and drop blank/null entries.
  4. If you need URLs with schemes, confirm Utils.getHost/Utils.getPort accept that form for your client version.

Example fix

// before
bootstrap.servers=localhost
// after
bootstrap.servers=localhost:9092
Defensive patterns

Strategy: validation

Validate before calling

// Validate each bootstrap entry before constructing the client
for (String url : bootstrapServers) {
  if (url == null || url.isEmpty()) continue;
  if (Utils.getHost(url) == null || Utils.getPort(url) == null)
    throw new IllegalArgumentException("Bad bootstrap url (need host:port): " + url);
}

Try / catch

try { BootstrapConfiguration.enabled(urls, dns, t, backoff); } catch (ConfigException e) { if (e.message.contains('Invalid url in bootstrap')) { /* fix bootstrap.servers */ } else throw e; }

Prevention

When it happens

Trigger: Inside the for loop at line 47, if host==null || port==null then throw ConfigException("Invalid url in bootstrap.servers: <url>"). Triggered by entries like 'localhost' (no port), ':9092' (no host), 'kafka://' (scheme only), or empty fragments.

Common situations: Passing 'localhost' instead of 'localhost:9092'; using a URL with a scheme but no host/port; trailing commas producing empty entries; copy-paste from docs that omit the port.

Related errors


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