openzipkin/zipkin · error · IllegalArgumentException

%s has an empty host

Error message

%s has an empty host

What it means

Thrown by HostAndPort.fromString when, after stripping the port and any brackets, the host portion is empty — e.g. ':9042', '[]:9042', or an empty string. A contact point must name a host.

Source

Thrown at zipkin-storage/cassandra/src/main/java/zipkin2/storage/cassandra/internal/HostAndPort.java:74

    int endHostIndex = hostPort.length();
    if (hostPort.startsWith("[")) { // Bracketed IPv6
      endHostIndex = hostPort.lastIndexOf(']') + 1;
      host = hostPort.substring(1, endHostIndex == 0 ? 1 : endHostIndex - 1);
      if (!Endpoint.newBuilder().parseIp(host)) { // reuse our IPv6 validator
        throw new IllegalArgumentException(hostPort + " contains an invalid IPv6 literal");
      }
    } else {
      int colonIndex = hostPort.indexOf(':'), nextColonIndex = hostPort.lastIndexOf(':');
      if (colonIndex >= 0) {
        if (colonIndex == nextColonIndex) { // only 1 colon
          host = hostPort.substring(0, colonIndex);
          endHostIndex = colonIndex;
        } else if (!Endpoint.newBuilder().parseIp(hostPort)) { // reuse our IPv6 validator
          throw new IllegalArgumentException(hostPort + " is an invalid IPv6 literal");
        }
      }
    }
    if (host.isEmpty()) throw new IllegalArgumentException(hostPort + " has an empty host");
    if (endHostIndex + 1 < hostPort.length() && hostPort.charAt(endHostIndex) == ':') {
      return new HostAndPort(host, validatePort(hostPort.substring(endHostIndex + 1), hostPort));
    }
    return new HostAndPort(host, defaultPort);
  }

  static int validatePort(String portString, String hostPort) {
    for (int i = 0, length = portString.length(); i < length; i++) {
      char c = portString.charAt(i);
      if (c >= '0' && c <= '9') continue; // isDigit
      throw new IllegalArgumentException(hostPort + " has an invalid port");
    }
    int result = Integer.parseInt(portString);
    if (result == 0 || result > 0xffff) {
      throw new IllegalArgumentException(hostPort + " has an invalid port");
    }
    return result;
  }

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Include the host: 'cassandra:9042'.
  2. Default empty host config values (e.g. to 'localhost') or fail config validation with a clearer message.
  3. Skip blank entries when parsing comma-separated contact-point lists.

Example fix

# before
CASSANDRA_CONTACT_POINTS=:9042

# after
CASSANDRA_CONTACT_POINTS=cassandra:9042
Defensive patterns

Strategy: validation

Validate before calling

if (hostPort == null || hostPort.isBlank() || hostPort.startsWith(":") || hostPort.startsWith("[]")) throw new IllegalArgumentException("Contact point needs a host: " + hostPort);

Try / catch

catch (IllegalArgumentException e) { if (e.getMessage().endsWith("has an empty host")) failConfigValidation(e.getMessage()); else throw e; }

Prevention

When it happens

Trigger: Strings like ':9042' (port only), '[]:9042' (empty brackets), or '' after trimming.

Common situations: Templated configs where the host placeholder is empty (KUBE_SERVICE_NAME unset); string splitting that leaves an empty element.

Related errors


AI-assisted analysis of openzipkin/zipkin@878ce2a1fa (2026-08-14). Data as JSON: /api/errors/6efaa563f1ea844e. Report an issue: GitHub.