eclipse-vertx/vert.x · error · IllegalArgumentException

port p must be < 65535

Error message

port p must be < 65535

What it means

SocketAddressImpl's (int port, String host) constructor rejects port values above 65535 with IllegalArgumentException. TCP/UDP ports are 16-bit; anything larger cannot be a valid port. Note the check is strict '> 65535', so 0 and negative are currently accepted by this check.

Source

Thrown at vertx-core/src/main/java/io/vertx/core/net/impl/SocketAddressImpl.java:64

    this.path = null;
    this.port= address.getPort();
    this.host = address.getHostString();
    if (address.isUnresolved()) {
      this.hostName = address.getHostName();
      this.ipAddress = null;
    } else {
      String host = address.getHostString();
      if (NetUtil.isValidIpV4Address(host) || NetUtil.isValidIpV6Address(host)) {
        host = null;
      }
      this.hostName = host;
      this.ipAddress = address.getAddress();
    }
  }

  public SocketAddressImpl(int port, String host) {
    if (port > 65535) {
      throw new IllegalArgumentException("port p must be < 65535");
    }
    this.path = null;
    this.port = port;
    if (NetUtil.isValidIpV4Address(host)) {
      InetAddress ip;
      try {
        ip = InetAddress.getByAddress(NetUtil.createByteArrayFromIpAddressString(host));
      } catch (UnknownHostException e) {
        throw new VertxException(e);
      }
      this.host = host;
      this.hostName = null;
      this.ipAddress = ip;
    } else if (NetUtil.isValidIpV6Address(host)) {
      Inet6Address ip = NetUtil.getByName(host);
      this.host = host;
      this.hostName = null;
      this.ipAddress = ip;

View on GitHub (pinned to fb308bd8c3)

Solutions

  1. Validate 0 <= port <= 65535 before calling the API
  2. Fix the config value to a valid port
  3. Check parsing logic that extracts the port from a string (Integer.parseInt on the substring after ':')

Example fix

// before
int port = Integer.parseInt(args[1]); // e.g. 808080
SocketAddress addr = SocketAddress.inetSocketAddress(port, "example.com");
// after
int port = Integer.parseInt(args[1]);
if (port < 0 || port > 65535) throw new IllegalArgumentException("invalid port: " + port);
SocketAddress addr = SocketAddress.inetSocketAddress(port, "example.com");
Defensive patterns

Strategy: validation

Validate before calling

if (port < 0 || port > 65535) throw new IllegalArgumentException("invalid port: " + port);

Try / catch

try {
  addr = SocketAddress.inetSocketAddress(port, host);
} catch (IllegalArgumentException e) {
  // reject config, surface a clear message
}

Prevention

When it happens

Trigger: Calling SocketAddress.inetSocketAddress(port, host) with port > 65535, typically a config value or a parsed string that is not a real port (e.g. '808080'), or combining host:port where the port portion was mis-parsed.

Common situations: Config files with 'port': 99999, parsing 'host:port' strings with wrong delimiter, byte-shift arithmetic errors producing values like 655360.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of eclipse-vertx/vert.x@fb308bd8c3 (2026-09-06). Data as JSON: /api/errors/352eecafca9ce8ea. Report an issue: GitHub.