apache/flink · error · NullPointerException
address is null
Error message
address is null
What it means
NetUtils.ipAddressToUrlString explicitly rejects a null InetAddress with a NullPointerException carrying the message 'address is null'. Only Inet4Address and Inet6Address are handled afterwards. It fires when callers pass an address that was never resolved or a field that was never set.
Source
Thrown at flink-core/src/main/java/org/apache/flink/util/NetUtils.java:279
* @param host The hostname, IPv4 or IPv6 address
* @param port The port
* @return host:port where host will be normalized if it is an IPv6 address
*/
public static String unresolvedHostAndPortToNormalizedString(String host, int port) {
Preconditions.checkArgument(isValidHostPort(port), "Port is not within the valid range,");
return unresolvedHostToNormalizedString(host) + ":" + port;
}
/**
* Encodes an IP address properly as a URL string. This method makes sure that IPv6 addresses
* have the proper formatting to be included in URLs.
*
* @param address The IP address to encode.
* @return The proper URL string encoded IP address.
*/
public static String ipAddressToUrlString(InetAddress address) {
if (address == null) {
throw new NullPointerException("address is null");
} else if (address instanceof Inet4Address) {
return address.getHostAddress();
} else if (address instanceof Inet6Address) {
return getIPv6UrlRepresentation((Inet6Address) address);
} else {
throw new IllegalArgumentException("Unrecognized type of InetAddress: " + address);
}
}
/**
* Encodes an IP address and port to be included in URL. in particular, this method makes sure
* that IPv6 addresses have the proper formatting to be included in URLs.
*
* @param address The address to be included in the URL.
* @param port The port for the URL address.
* @return The proper URL string encoded IP address and port.
*/
public static String ipAddressAndPortToUrlString(InetAddress address, int port) {View on GitHub (pinned to 2f3c205e92)
Solutions
- Find who passes null: usually a DNS/lookup step whose failure path returned null instead of throwing.
- Resolve the address before calling, or skip URL construction when the address is absent.
- Prefer InetSocketAddress-based APIs (socketAddressToUrlString) if you have host+port, keeping the null/resolve check in one place.
Example fix
// before String url = NetUtils.ipAddressToUrlString(lookupHost(host)); // returns null on failure // after InetAddress addr = Objects.requireNonNull(lookupHost(host), "host not resolved: " + host); String url = NetUtils.ipAddressToUrlString(addr);
Defensive patterns
Strategy: validation
Validate before calling
InetAddress addr = Objects.requireNonNull(address, "address must be resolved before URL conversion"); String url = NetUtils.ipAddressToUrlString(addr);
Try / catch
if (address == null) { throw new IllegalStateException("address not resolved for " + host); } // fail before calling the API instead of catching NPE Prevention
- Never let lookup helpers return null; throw UnknownHostException instead.
- Centralize address resolution in one component.
When it happens
Trigger: Calling NetUtils.ipAddressToUrlString(null) or ipAddressAndPortToUrlString(null, port); passing an InetAddress obtained from a failed lookup helper that returns null on error.
Common situations: glue code that maps 'lookup failed' to null; constructing URLs for a service whose address field is optional and unset; refactors that drop the resolution step.
Related errors
- Id must not be null.
- The given host:port ('{}') doesn't contain a valid host
- The given host:port ('{}') doesn't contain a valid port
- The given host:port ('{}') is invalid
- Could not find a free permitted port on the machine.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/0980e591f98efdbc.
Report an issue: GitHub.