apache/kafka · error · ConfigException

Invalid url in bootstrap.servers: {url}

Error message

Invalid url in bootstrap.servers: {url}

What it means

ConfigException thrown inside ClientUtils.parseAndValidateAddresses when Utils.getHost or Utils.getPort returns null for a non-empty bootstrap entry, meaning the entry cannot be split into a host and a numeric port. This is the canonical producer/consumer/admin bootstrap validation path and runs whenever a client resolves its initial broker list.

Source

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

    public static List<InetSocketAddress> parseAndValidateAddresses(AbstractConfig config) {
        List<String> urls = config.getList(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG);
        String clientDnsLookupConfig = config.getString(CommonClientConfigs.CLIENT_DNS_LOOKUP_CONFIG);
        return parseAndValidateAddresses(urls, clientDnsLookupConfig);
    }

    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 c31c9215e1)

Solutions

  1. Read the offending 'url' token in the message and confirm the expected 'host:port' shape.
  2. Fix the specific bootstrap.servers entry so host and numeric port are both present.
  3. Confirm the entry is comma-separated from neighbours and contains no scheme prefix or surrounding whitespace.

Example fix

// before
bootstrap.servers=kafka-broker
// after
bootstrap.servers=kafka-broker:9092
Defensive patterns

Strategy: validation

Validate before calling

// Same root cause as [11] — ClientUtils.parseAndValidateAddresses throws
// ConfigException when getHost(url) or getPort(url) returns null.
// Pre-validate with the exact helpers the library itself uses:
import org.apache.kafka.common.utils.Utils;

static List<String> sanitizeBootstrap(List<String> raw) {
    List<String> ok = new ArrayList<>();
    for (String url : raw) {
        if (url == null || url.isBlank()) continue;
        if (Utils.getHost(url) == null || Utils.getPort(url) == null)
            throw new IllegalArgumentException("Invalid bootstrap url: " + url);
        ok.add(url);
    }
    if (ok.isEmpty()) throw new IllegalArgumentException("No valid bootstrap urls supplied");
    return ok;
}
// props.put(BOOTSTRAP_SERVERS_CONFIG, sanitizeBootstrap(rawList));

Type guard

static boolean isParsableBootstrapUrl(String url) {
    return url != null && !url.isBlank()
        && Utils.getHost(url) != null
        && Utils.getPort(url) != null;
}

Try / catch

try {
    producer = new KafkaProducer<>(props);
} catch (ConfigException e) {
    if (e.getMessage().startsWith("Invalid url in bootstrap.servers")) {
        // config is wrong; recreating with the same props will fail identically.
        throw new ConfigurationException("Fix bootstrap.servers: " + e.getMessage(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Passing bootstrap.servers containing an entry without a port ('brokerA'), without a host (':9092'), or with a non-numeric port token. Reached from any client constructor that calls parseAndValidateAddresses, including KafkaProducer, KafkaConsumer, AdminClient, KafkaStreams, and Connect workers.

Common situations: Typo in a properties file, a ${BROKER_URL} placeholder that resolves without a port, copy-pasting a URL with a scheme ('kafka://host'), or mixing whitespace separators where a comma is required.

Related errors


AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03). Data as JSON: /data/errors/e426fbbd84e54a61.json. Report an issue: GitHub.