quarkusio/quarkus · error · IllegalArgumentException

Invalid port number

Error message

Invalid port number

What it means

proxyAddress(String, int) validates that the port is within 1–65535. An out-of-range port throws IllegalArgumentException 'Invalid port number', unless the host is the special value "none" used to disable proxying. This mirrors standard socket port validation.

Source

Thrown at extensions/resteasy-reactive/rest-client/runtime/src/main/java/io/quarkus/rest/client/reactive/runtime/RestClientBuilderImpl.java:232

    @Override
    public RestClientBuilderImpl hostnameVerifier(HostnameVerifier hostnameVerifier) {
        clientBuilder.hostnameVerifier(hostnameVerifier);
        return this;
    }

    @Override
    public RestClientBuilderImpl followRedirects(final boolean follow) {
        this.followRedirects = follow;
        return this;
    }

    @Override
    public RestClientBuilderImpl proxyAddress(final String proxyHost, final int proxyPort) {
        if (proxyHost == null) {
            throw new IllegalArgumentException("proxyHost must not be null");
        }
        if ((proxyPort <= 0 || proxyPort > 65535) && !proxyHost.equals("none")) {
            throw new IllegalArgumentException("Invalid port number");
        }
        this.proxyHost = proxyHost;
        this.proxyPort = proxyPort;

        return this;
    }

    public RestClientBuilderImpl proxyPassword(String proxyPassword) {
        this.proxyPassword = proxyPassword;
        return this;
    }

    public RestClientBuilderImpl proxyUser(String proxyUser) {
        this.proxyUser = proxyUser;
        return this;
    }

    public RestClientBuilderImpl nonProxyHosts(String nonProxyHosts) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Pass a valid port in the 1–65535 range
  2. Use proxyAddress("none", arbitraryPort) to disable the proxy instead of port 0
  3. Validate/parse the port from config with Integer.parseInt and range-check before calling

Example fix

// before
builder.proxyAddress("proxy.corp.com", 0);
// after
builder.proxyAddress("proxy.corp.com", 8080);
Defensive patterns

Strategy: validation

Validate before calling

static void requireValidPort(int port) {
    if (port <= 0 || port > 65535) throw new IllegalArgumentException("Port out of range: " + port);
}
// call before builder.proxyAddress(host, port)

Type guard

static boolean isValidPort(int p) { return p > 0 && p <= 65535; }

Try / catch

try {
    builder.proxyAddress(host, port);
} catch (IllegalArgumentException e) {
    if (e.getMessage().equals("Invalid port number")) {
        throw new IllegalArgumentException("Proxy port must be 1-65535, got: " + port);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling builder.proxyAddress(host, 0), negative ports, or ports above 65535 (e.g. int overflow or a misparsed value); passing a placeholder port with host "none" is exempted.

Common situations: Parsing a port string that lost digits or was concatenated incorrectly; config holding 0 as 'default'; using an unsigned-port value >65535 from a bad calculation; forgetting that proxyAddress(host, 0) is invalid even as a 'no proxy' sentinel — "none" is the sentinel.

Related errors


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