apache/flink · error · IllegalArgumentException

hostPort should not be null or empty

Error message

hostPort should not be null or empty

What it means

NetUtils.parseHostnamePort validates a 'host:port' string by internally constructing a URL (prepending http:// when no scheme exists) and inspecting host/port. The first guard rejects null, empty, or whitespace-only input with IllegalArgumentException, since no host:port can be parsed from it.

Source

Thrown at flink-core/src/main/java/org/apache/flink/util/NetUtils.java:107

     */
    public static InetSocketAddress parseHostPortAddress(String hostPort) {
        URL url = validateHostPortString(hostPort);
        return new InetSocketAddress(url.getHost(), url.getPort());
    }

    /**
     * Validates if the given String represents a hostname:port.
     *
     * <p>Works also for ipv6.
     *
     * <p>See:
     * http://stackoverflow.com/questions/2345063/java-common-way-to-validate-and-convert-hostport-to-inetsocketaddress
     *
     * @return URL object for accessing host and port
     */
    private static URL validateHostPortString(String hostPort) {
        if (StringUtils.isNullOrWhitespaceOnly(hostPort)) {
            throw new IllegalArgumentException("hostPort should not be null or empty");
        }
        try {
            URL u =
                    (hostPort.toLowerCase().startsWith("http://")
                                    || hostPort.toLowerCase().startsWith("https://"))
                            ? new URL(hostPort)
                            : new URL("http://" + hostPort);
            if (u.getHost() == null) {
                throw new IllegalArgumentException(
                        "The given host:port ('" + hostPort + "') doesn't contain a valid host");
            }
            if (u.getPort() == -1) {
                throw new IllegalArgumentException(
                        "The given host:port ('" + hostPort + "') doesn't contain a valid port");
            }
            return u;
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException(

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Provide a non-empty host:port value in the configuration entry named in your setup code.
  2. Filter blank entries before parsing comma-separated address lists: Arrays.stream(list).filter(s -> !s.isBlank()).
  3. Guard nullable sources with a default address or a fail-fast message naming the missing option.
  4. Trim input and validate format (matches 'host:port' with numeric port) before calling parseHostnamePort.

Example fix

// before
InetSocketAddress addr = NetUtils.parseHostnamePort(System.getenv("JM_ADDRESS")); // env unset -> IAE

// after
String address = System.getenv("JM_ADDRESS");
if (address == null || address.isBlank()) {
    address = "localhost:8081"; // or throw with a clear message
}
InetSocketAddress addr = NetUtils.parseHostnamePort(address);
Defensive patterns

Strategy: validation

Validate before calling

if (hostPort == null || hostPort.isBlank()) {
    throw new IllegalArgumentException("host:port must be non-empty (check address config/env var)");
}
InetSocketAddress addr = NetUtils.parseHostnamePort(hostPort);

Prevention

When it happens

Trigger: Calling NetUtils.parseHostnamePort(s) with s null, empty, or whitespace — e.g. an address option that was never set, a trimmed-to-empty env var, or a list entry that is a blank string.

Common situations: REST/JobManager address configuration (e.g. 'host:port' style options) missing from flink-conf; environment variables like JOBMANAGER_HOST expanded to empty in containers; string splitting producing empty tokens from trailing commas ('a:1,b:2,').

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/c67dbf5e9e88d73b. Report an issue: GitHub.