openzipkin/zipkin · error · NullPointerException

hostPort == null

Error message

hostPort == null

What it means

HostAndPort.fromString(hostPort, defaultPort) throws NullPointerException('hostPort == null') when the contact-point string is null. It is a plain fail-fast guard before any parsing; contact points must be non-null strings.

Source

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

  @Override public int hashCode() {
    int h = 1;
    h *= 1000003;
    h ^= (host == null) ? 0 : host.hashCode();
    h *= 1000003;
    h ^= port;
    return h;
  }

  @Override public String toString() {
    return "HostAndPort{host=" + host + ", port=" + port + "}";
  }

  /**
   * Constructs a host-port pair from the given string, defaulting to the indicated port if absent
   */
  public static HostAndPort fromString(String hostPort, int defaultPort) {
    if (hostPort == null) throw new NullPointerException("hostPort == null");

    String host = hostPort;
    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");
        }

View on GitHub (pinned to 878ce2a1fa)

Solutions

  1. Supply a non-null host or host:port string such as 'localhost' or '127.0.0.1:9042'.
  2. Default the config value at load time (e.g. getenvOrDefault('CASSANDRA_CONTACT_POINTS', 'localhost')).
  3. Filter null/blank entries before parsing lists of contact points.

Example fix

// before
HostAndPort.fromString(env.get("HOST"), 9042); // env.get -> null

// after
HostAndPort.fromString(env.getOrDefault("HOST", "localhost"), 9042);
Defensive patterns

Strategy: validation

Validate before calling

String hp = env.getOrDefault("CASSANDRA_CONTACT_POINTS", "localhost");
if (hp == null || hp.isBlank()) throw new IllegalArgumentException("Contact point must not be empty");
HostAndPort.fromString(hp, 9042);

Prevention

When it happens

Trigger: Passing a null contact point string, e.g. from CASSANDRA_CONTACT_POINTS processing where a split/trim produced null or a config lookup returned null.

Common situations: Config property missing so the loader hands null into the parser; string splitting logic that yields null elements.

Related errors


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