{"record":{"id":"0980e591f98efdbc","repo":"apache/flink","slug":"address-is-null","errorCode":null,"errorMessage":"address is null","messagePattern":"address is null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/NetUtils.java","lineNumber":279,"sourceCode":"     * @param host The hostname, IPv4 or IPv6 address\n     * @param port The port\n     * @return host:port where host will be normalized if it is an IPv6 address\n     */\n    public static String unresolvedHostAndPortToNormalizedString(String host, int port) {\n        Preconditions.checkArgument(isValidHostPort(port), \"Port is not within the valid range,\");\n        return unresolvedHostToNormalizedString(host) + \":\" + port;\n    }\n\n    /**\n     * Encodes an IP address properly as a URL string. This method makes sure that IPv6 addresses\n     * have the proper formatting to be included in URLs.\n     *\n     * @param address The IP address to encode.\n     * @return The proper URL string encoded IP address.\n     */\n    public static String ipAddressToUrlString(InetAddress address) {\n        if (address == null) {\n            throw new NullPointerException(\"address is null\");\n        } else if (address instanceof Inet4Address) {\n            return address.getHostAddress();\n        } else if (address instanceof Inet6Address) {\n            return getIPv6UrlRepresentation((Inet6Address) address);\n        } else {\n            throw new IllegalArgumentException(\"Unrecognized type of InetAddress: \" + address);\n        }\n    }\n\n    /**\n     * Encodes an IP address and port to be included in URL. in particular, this method makes sure\n     * that IPv6 addresses have the proper formatting to be included in URLs.\n     *\n     * @param address The address to be included in the URL.\n     * @param port The port for the URL address.\n     * @return The proper URL string encoded IP address and port.\n     */\n    public static String ipAddressAndPortToUrlString(InetAddress address, int port) {","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/NetUtils.java#L261-L297","documentation":"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.","triggerScenarios":"Calling NetUtils.ipAddressToUrlString(null) or ipAddressAndPortToUrlString(null, port); passing an InetAddress obtained from a failed lookup helper that returns null on error.","commonSituations":" 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.","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."],"exampleFix":"// before\nString url = NetUtils.ipAddressToUrlString(lookupHost(host)); // returns null on failure\n\n// after\nInetAddress addr = Objects.requireNonNull(lookupHost(host), \"host not resolved: \" + host);\nString url = NetUtils.ipAddressToUrlString(addr);","handlingStrategy":"validation","validationCode":"InetAddress addr = Objects.requireNonNull(address, \"address must be resolved before URL conversion\");\nString url = NetUtils.ipAddressToUrlString(addr);","typeGuard":null,"tryCatchPattern":"if (address == null) { throw new IllegalStateException(\"address not resolved for \" + host); } // fail before calling the API instead of catching NPE","preventionTips":["Never let lookup helpers return null; throw UnknownHostException instead.","Centralize address resolution in one component."],"tags":["network","null-safety","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}