quarkusio/quarkus · error · IllegalArgumentException

invalid host

Error message

invalid host

What it means

UriBuilderImpl.host(String) throws 'invalid host' when the host argument is non-null but the empty string. An empty host would produce an invalid authority (http:///path), so the builder rejects it per the JAX-RS contract. Passing null is allowed and clears the host.

Source

Thrown at independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/jaxrs/UriBuilderImpl.java:343

            userInfo = uri.getRawUserInfo();
            host = uri.getHost();
            port = uri.getPort();
            path = uri.getRawPath();
            query = uri.getRawQuery();

        }
        return this;

    }

    public UriBuilder userInfo(String ui) {
        this.userInfo = ui;
        return this;
    }

    public UriBuilder host(String host) throws IllegalArgumentException {
        if (host != null && host.equals(""))
            throw new IllegalArgumentException("invalid host");
        this.host = host;
        return this;
    }

    public UriBuilder port(int port) throws IllegalArgumentException {
        if (port < -1)
            throw new IllegalArgumentException("invalid port");
        this.port = port;
        return this;
    }

    public UriBuilder encode(boolean encode) {
        this.encode = encode;
        return this;
    }

    protected static String paths(boolean encode, String basePath, String... segments) {
        String path = basePath;

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a real hostname, or null to unset the host - never the empty string
  2. Validate/trim the configured host and skip the call when blank
  3. Take the host from URI.getHost() instead of manual splitting
  4. Guard with a blank check at your call site for a clearer failure

Example fix

// before: builder.host(config.host().trim()); // throws if host is empty // after: String h = config.host().trim(); if (!h.isEmpty()) { builder.host(h); }
Defensive patterns

Strategy: validation

Validate before calling

static String requireHost(String host) {
    if (host == null) return null; // null is allowed (clears host)
    String h = host.trim();
    if (h.isEmpty()) throw new IllegalArgumentException('host must not be blank');
    return h;
}

Type guard

static boolean isValidHost(String host) {
    return host == null || !host.isBlank();
}

Try / catch

try {
    builder.host(host);
} catch (IllegalArgumentException e) {
    throw new IllegalArgumentException('host was the empty string; expected a hostname or null: ' + host, e);
}

Prevention

When it happens

Trigger: Calling builder.host("") directly; a host extracted via regex/split that produced an empty group; a configured URL like 'http://:8080/' where the host group is empty; env substitution leaving the host variable empty.

Common situations: Parsing 'http://:8080/' where the host token is empty; HOST env var unset or blank; String.split/subset on a missing delimiter yielding an empty token; blank default values in configuration.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/74fbd992eca9de8e. Report an issue: GitHub.