apache/kafka · error · ConfigException

Invalid port in bootstrap.servers: {}

Error message

Invalid port in bootstrap.servers: {}

What it means

ConfigException thrown by BootstrapConfiguration.enabled when Utils.getPort(url) raises IllegalArgumentException during parsing — i.e. the port segment is present but not a valid integer. Distinct from 'Invalid url' (which fires when port is null); this fires when the port token cannot be parsed as a number.

Source

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

                                   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. Use a numeric port in the valid range 0-65535, conventionally 9092 for Kafka.
  2. Check for hidden/non-ASCII digits in the config (e.g. from copy-paste).
  3. Validate each entry programmatically before constructing the client (see validationCode).
  4. If templating the port, ensure the variable resolves to an integer literal.

Example fix

// before
bootstrap.servers=broker1:9o92
// after
bootstrap.servers=broker1:9092
Defensive patterns

Strategy: validation

Validate before calling

// Pre-validate the port parses as an int in range
for (String url : bootstrapServers) {
  String[] parts = url.split(":");
  if (parts.length == 2) {
    int p = Integer.parseInt(parts[1]); // NumberFormatException surfaces the bad token
    if (p < 0 || p > 65535) throw new IllegalArgumentException("port out of range: " + url);
  }
}

Try / catch

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

Prevention

When it happens

Trigger: The inner try at line 49-51 calls getPort(url); if it throws IllegalArgumentException (caught at line 53), the message becomes 'Invalid port in bootstrap.servers: <url>'. Triggered by entries like 'host:abc', 'host:999999999' (out of range), or 'host:-1'.

Common situations: Typing a non-numeric port ('host:kafka'); pasting a port with a unicode lookalike digit; out-of-range port (>65535); negative port from a templating bug.

Related errors


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