quarkusio/quarkus · error · IllegalArgumentException

invalid port

Error message

invalid port

What it means

UriBuilderImpl.port(int) throws 'invalid port' when the port is less than -1. By convention -1 means unset/default port and 0..65535 are valid; anything below -1 is rejected per the JAX-RS contract. Ports above 65535 are NOT rejected here - they fail later at request or normalization time.

Source

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

        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;
        if (path == null)
            path = "";
        for (String segment : segments) {
            if ("".equals(segment))
                continue;
            if (path.endsWith("/")) {
                if (segment.startsWith("/")) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Validate the port before calling: accept only -1 or 0..65535, else use a default or fail
  2. Use -1 explicitly as the only 'unset' sentinel
  3. Range-check parsed values before use and catch IllegalArgumentException around .port(...) to log the raw value
  4. Clamp derived values: Math.max(-1, basePort + offset)

Example fix

// before: int port = basePort + offset; builder.port(port); // throws if negative // after: int port = Math.max(-1, basePort + offset); if (port > 65535) throw new IllegalArgumentException('port out of range: ' + port); builder.port(port);
Defensive patterns

Strategy: validation

Validate before calling

static int requireValidPort(int port) {
    if (port < -1 || port > 65535)
        throw new IllegalArgumentException('port must be -1 (unset) or 0..65535, got: ' + port);
    return port;
}

Type guard

static boolean isValidPort(int port) {
    return port >= -1 && port <= 65535;
}

Try / catch

try {
    builder.port(port);
} catch (IllegalArgumentException e) {
    throw new IllegalArgumentException('configured port is invalid (must be >= -1): ' + port, e);
}

Prevention

When it happens

Trigger: Calling builder.port(-2) or lower, usually from a parsed config value that was negative, offset arithmetic underflowing (basePort + offset), or an unvalidated negative sentinel like -999.

Common situations: Corrupted or placeholder-substituted config yielding a negative number; service discovery returning a negative port; derived-port arithmetic underflow.

Related errors


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