apache/hadoop · error · IllegalArgumentException
Address should be <host>:<port>, but it is {}
Error message
Address should be <host>:<port>, but it is {} What it means
IllegalArgumentException from NetUtils.getPortFromHostPortString when splitting the input on ':' does not produce exactly two tokens. Anything other than a single-colon 'host:port' fails: a bare host, 'host:port:extra', empty string, or an IPv6 literal (whose colons yield many tokens). The message echoes the offending input. Note the port part is then parsed by Integer.parseInt, so a non-numeric port throws NumberFormatException instead.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java:784
* @return hort port string.
*/
public static String getHostPortString(InetSocketAddress addr) {
return addr.getHostName() + ":" + addr.getPort();
}
/**
* Get port as integer from host port string like host:port.
*
* @param addr host + port string like host:port.
* @return an integer value representing the port.
* @throws IllegalArgumentException if the input is not in the correct format.
*/
public static int getPortFromHostPortString(String addr)
throws IllegalArgumentException {
String[] hostport = addr.split(":");
if (hostport.length != 2) {
String errorMsg = "Address should be <host>:<port>, but it is " + addr;
throw new IllegalArgumentException(errorMsg);
}
return Integer.parseInt(hostport[1]);
}
/**
* Checks if {@code host} is a local host name and return {@link InetAddress}
* corresponding to that address.
*
* @param host the specified host
* @return a valid local {@link InetAddress} or null
* @throws SocketException if an I/O error occurs
*/
public static InetAddress getLocalInetAddress(String host)
throws SocketException {
if (host == null) {
return null;
}
InetAddress addr = null;View on GitHub (pinned to 2add963021)
Solutions
- Pass exactly 'host:port' — strip any 'scheme://' prefix first
- For IPv6, use a URI-based parse (URI.create("dummyscheme://[::1]:8080").getPort()) instead of this helper
- Pre-check with addr.split(":").length == 2 (and a numeric last token) before calling, to give a clearer error
Example fix
// before
int port = NetUtils.getPortFromHostPortString("http://host:8080"); // 3 tokens -> IllegalArgumentException
// after
String hp = "http://host:8080".replaceFirst("^\\w+://", ""); // "host:8080"
int port = NetUtils.getPortFromHostPortString(hp); Defensive patterns
Strategy: validation
Validate before calling
String[] parts = addr.split(":");
if (parts.length != 2 || !parts[1].matches("\\d+")) {
throw new IllegalStateException("expected host:port, got: " + addr);
} Type guard
static boolean isHostPort(String addr) {
String[] p = addr.split(":");
return p.length == 2 && p[1].matches("\\d+");
} Prevention
- Strip scheme:// prefixes before calling this helper
- Do not use this helper for IPv6 — parse with URI instead
- Include the numeric-port check yourself to get a clearer error than NumberFormatException
When it happens
Trigger: getPortFromHostPortString("myhost") (no port); getPortFromHostPortString("http://myhost:8080") (scheme adds a colon); getPortFromHostPortString("::1:8080") or any unbracketed IPv6 address.
Common situations: Passing URLs where a host:port is expected; forgetting to strip the scheme; IPv6 addresses not bracketed (even bracketed '[::1]:8080' fails because split(':') sees 3+ tokens — this helper is effectively IPv4/hostname only).
Related errors
- Wrong length: {digest.length}
- Wrong length: {hex.length}
- Not a hex character: {c}
- No schema options are provided
- No codec option is provided
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/44b34c106b386dcb.
Report an issue: GitHub.