prestodb/presto · error · IllegalArgumentException
Port number out of range:
Error message
Port number out of range:
What it means
After fromString successfully parses the port as an integer it must still pass isValidPort (0..65535). Integers outside that range — e.g. 70000 or 999999999 — parse fine but are not legal ports, so parsing fails with "Port number out of range" quoting the full hostPortString.
Source
Thrown at presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java:215
host = hostPortString;
}
}
int port = NO_PORT;
if (portString != null && portString.length() != 0) {
// Try to parse the whole port string as a number.
// JDK7 accepts leading plus signs. We don't want to.
if (portString.startsWith("+")) {
throw new IllegalArgumentException("Unparseable port number: " + hostPortString);
}
try {
port = Integer.parseInt(portString);
}
catch (NumberFormatException e) {
throw new IllegalArgumentException("Unparseable port number: " + hostPortString);
}
if (!isValidPort(port)) {
throw new IllegalArgumentException("Port number out of range: " + hostPortString);
}
}
return new HostAddress(host, port);
}
public static HostAddress fromUri(URI httpUri)
{
String host = httpUri.getHost();
int port = httpUri.getPort();
if (port < 0) {
return fromString(host);
}
else {
return fromParts(host, port);
}
}
View on GitHub (pinned to 55bb57d202)
Solutions
- Check the port is within 0..65535 (operationally 1..65535) before parsing
- Correct the port value in the config/URI that supplies it
- Reuse isValidPort-style validation at the config boundary so the failure happens earlier
- Generate test ports with RandomPort utilities instead of arbitrary numbers
Example fix
// before
HostAddress.fromString("localhost:70000");
// after
HostAddress.fromString("localhost:65535");
// or guard first
if (port < 1 || port > 65535) throw new IllegalArgumentException("bad port"); Defensive patterns
Strategy: validation
Validate before calling
int idx = hostPort.lastIndexOf(':');
int p = Integer.parseInt(hostPort.substring(idx + 1).trim());
if (p < 0 || p > 65535) {
throw new IllegalArgumentException("Port number out of range: " + p);
} Try / catch
try {
addr = HostAddress.fromString(hostPort);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid port in address: " + hostPort, e);
} Prevention
- Range-check ports 0..65535 at the config boundary
- Don't conflate ports with other numeric identifiers
- Use well-known scheme defaults (80/443) instead of ad-hoc large numbers
When it happens
Trigger: HostAddress.fromString("host:70000") or "host:65536" — syntactically numeric, int-parseable, but outside the valid 0..65535 port range.
Common situations: Confusing port with other numeric fields (PID, inode); decimal/hex mixups (0x10000 typed as 10000 in wrong base); randomly generated invalid ports in tests; shifted digits from typos.
Related errors
- Port is invalid:
- host contains a port declaration:
- Unparseable port number:
- Invalid bracketed host/port:
- ARROW_FLIGHT_CLIENT_ERROR
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/dc1ec957d0060633.
Report an issue: GitHub.