openzipkin/zipkin · error · IllegalArgumentException

%s has an invalid port

Error message

%s has an invalid port

What it means

validatePort throws IllegalArgumentException('%s has an invalid port') when the port substring contains a non-digit character. The parser scans each char and rejects anything outside '0'-'9' before Integer.parseInt, so values like '90a2' or '9042 ' (whitespace) fail here with the full host:port string in the message.

Source

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

          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. Fix the port to digits only, e.g. 'host:9042'.
  2. Trim whitespace and split lists on ',' before calling fromString.
  3. Normalize config files (strip CR) or use env vars instead of multi-line properties.

Example fix

// before
for (String hp : contactPoints) HostAndPort.fromString(hp, 9042); // one entry: "host:9042\r"

// after
for (String hp : contactPoints) HostAndPort.fromString(hp.trim(), 9042);
Defensive patterns

Strategy: validation

Validate before calling

static boolean hasDigitsOnlyPort(String hostPort) {
  int c = hostPort.lastIndexOf(':');
  if (c < 0) return true;
  String p = hostPort.substring(c + 1);
  return !p.isEmpty() && p.chars().allMatch(ch -> ch >= '0' && ch <= '9');
}
if (!hasDigitsOnlyPort(trimmed)) throw new IllegalArgumentException("Port must be digits: " + hostPort);

Try / catch

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

Prevention

When it happens

Trigger: Passing 'host:9o42', 'host:9042,host2:9042' (un-split list), or a port with trailing whitespace/newline from a config file.

Common situations: CRLF line endings in properties files appending \r to the port; forgetting to split comma-separated CASSANDRA_CONTACT_POINTS before parsing.

Related errors


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