apache/druid · error · IllegalStateException

Unable to parse port out of

Error message

Unable to parse port out of %s

What it means

ServiceLocation.getPortFromString splits a "host:port"-style string and parses the second token as an integer port. When the token after the delimiter is missing or non-numeric, Integer.parseInt throws NumberFormatException and this ISE is raised wrapping it.

Solutions

  1. Ensure the server string includes a numeric port: change "broker.internal" to "broker.internal:8082".
  2. Validate the port substring with Integer.parseInt yourself before passing the host string in.
  3. Switch to constructing ServiceLocation directly with host and port ints instead of parsing strings.

Example fix

// before
String server = "broker.internal";
ServiceLocation loc = ServiceLocation.fromPlainText(server, tls, basePath);
// after
String server = "broker.internal:8082";
ServiceLocation loc = ServiceLocation.fromPlainText(server, tls, basePath);
Defensive patterns

Strategy: validation

Validate before calling

String portPart = server.contains(":") ? server.substring(server.lastIndexOf(':') + 1) : null;
if (portPart == null || !portPart.matches("\\d+")) {
  throw new IllegalArgumentException("Server string must be host:numericPort: " + server);
}

Prevention

When it happens

Trigger: Calling plaintextPort or tlsPort on a host string whose second split token is not a number — e.g. "broker.internal" (no port) or "broker.internal:http".

Common situations: Legacy configuration keys that list servers as host:port where the port was dropped or replaced by a hostname alias; IPv6 addresses confusing the splitter; migration from other discovery formats.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/0eaba595f37c9c78. Report an issue: GitHub.

Appendix: source

Thrown at server/src/main/java/org/apache/druid/rpc/ServiceLocation.java:160

  private static String getHostFromString(@NotNull String s)
  {
    Iterator<String> iterator = HOST_SPLITTER.split(s).iterator();
    ImmutableList<String> strings = ImmutableList.copyOf(iterator);
    return strings.get(0);
  }

  private static int getPortFromString(String s)
  {
    if (s == null) {
      return -1;
    }
    Iterator<String> iterator = HOST_SPLITTER.split(s).iterator();
    ImmutableList<String> strings = ImmutableList.copyOf(iterator);
    try {
      return Integer.parseInt(strings.get(1));
    }
    catch (NumberFormatException e) {
      throw new ISE(e, "Unable to parse port out of %s", strings.get(1));
    }
  }

  public String getHost()
  {
    return host;
  }

  /**
   * Returns a host:port string for the preferred port (TLS if available; plaintext otherwise).
   */
  public String getHostAndPort()
  {
    if (tlsPort > 0) {
      return host + ":" + tlsPort;
    } else {
      return host + ":" + plaintextPort;
    }

View on GitHub (pinned to 9b90983fd2)