prestodb/presto · error · IllegalArgumentException

host contains a port declaration:

Error message

host contains a port declaration: 

What it means

fromParts expects the host string to be a bare host (or IPv6 literal without port). If fromString(host) detects an embedded port in the host argument, fromParts rejects it because the port would conflict with the explicit port parameter. The port must be supplied via the separate port argument.

Source

Thrown at presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java:155

    /**
     * Build a HostAddress instance from separate host and port values.
     * <p>
     * <p>Note: Non-bracketed IPv6 literals are allowed.
     *
     * @param host the host string to parse.  Must not contain a port number.
     * @param port a port number from [0..65535]
     * @return if parsing was successful, a populated HostAddress object.
     * @throws IllegalArgumentException if {@code host} contains a port number,
     * or {@code port} is out of range.
     */
    public static HostAddress fromParts(String host, int port)
    {
        if (!isValidPort(port)) {
            throw new IllegalArgumentException("Port is invalid: " + port);
        }
        HostAddress parsedHost = fromString(host);
        if (parsedHost.hasPort()) {
            throw new IllegalArgumentException("host contains a port declaration: " + host);
        }
        return new HostAddress(parsedHost.host, port);
    }

    private static final Pattern BRACKET_PATTERN = Pattern.compile("^\\[(.*:.*)\\](?::(\\d*))?$");

    /**
     * Split a freeform string into a host and port, without strict validation.
     * <p>
     * Note that the host-only formats will leave the port field undefined.  You
     * can use {@link #withDefaultPort(int)} to patch in a default value.
     *
     * @param hostPortString the input string to parse.
     * @return if parsing was successful, a populated HostAddress object.
     * @throws IllegalArgumentException if nothing meaningful could be parsed.
     */
    @JsonCreator
    public static HostAddress fromString(String hostPortString)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Strip the port from the host string before calling fromParts
  2. Use HostAddress.fromString("host:port") to parse a combined string instead of fromParts
  3. Use HostAddress.fromUri(URI) when the source is a URI
  4. For IPv6 literals, pass the bracket-stripped address as host and the port separately

Example fix

// before
HostAddress.fromParts("example.com:8080", 9090);
// after
HostAddress.fromParts("example.com", 9090);
// or
HostAddress.fromString("example.com:8080");
Defensive patterns

Strategy: validation

Validate before calling

if (host != null && (host.contains(":") && !(host.startsWith("[") && host.endsWith("]")))) {
    throw new IllegalArgumentException("Host must not contain a port: " + host);
}

Try / catch

try {
    addr = HostAddress.fromParts(host, port);
} catch (IllegalArgumentException e) {
    // host string had embedded port; fall back to combined parse
    addr = HostAddress.fromString(host);
}

Prevention

When it happens

Trigger: Calling HostAddress.fromParts("example.com:8080", 9090) or fromParts("[::1]:8080", 9090) — i.e. passing a host string that still contains ":port" or a bracketed host-with-port.

Common situations: Splitting "host:port" config strings on the first colon only, leaving the port in the host; passing a full URI authority string as the host argument; IPv6 addresses where naive colon splitting fails.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/054ed25b8e416061. Report an issue: GitHub.