apache/kafka · error · ConfigException

Invalid port in bootstrap.servers: {}

Error message

Invalid port in bootstrap.servers: {}

What it means

ConfigException from ClientUtils.parseAndValidateAddresses when Utils.getPort(url) throws IllegalArgumentException — the port token is not a valid integer. Same shape as BootstrapConfiguration error 12 but raised during address resolution.

Source

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

    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.
     *
     * @param config client configs
     * @param time the time implementation
     * @param logContext the logging context
     *
     * @return configured ChannelBuilder based on the configs.

View on GitHub (pinned to 996fb4585a)

Solutions

  1. Use a numeric port in 0-65535 (typically 9092).
  2. Sanitize templated ports to integers.
  3. Pre-validate the list with a regex like ^(\w[\w.-]*):(\d{1,5})$ before calling.
  4. Inspect the offending url in the exception message.

Example fix

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

Strategy: validation

Validate before calling

for (String url : urls) {
  Integer port = null;
  try { port = Utils.getPort(url); } catch (IllegalArgumentException ignore) {}
  if (port == null || port < 0 || port > 65535)
    throw new IllegalArgumentException("Bad port in " + url);
}

Try / catch

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

Prevention

When it happens

Trigger: getPort(url) at line 131 throws IllegalArgumentException, caught at line 134, rethrown as ConfigException("Invalid port in bootstrap.servers: <url>"). Triggered by non-numeric, out-of-range, or negative port segments.

Common situations: Non-numeric port from a misconfigured environment variable; out-of-range port; copy-paste introducing a non-digit character.

Related errors


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