{"record":{"id":"cca24f77637927b1","repo":"apache/flink","slug":"unrecognized-type-of-inetaddress","errorCode":null,"errorMessage":"Unrecognized type of InetAddress: {}","messagePattern":"Unrecognized type of InetAddress: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/NetUtils.java","lineNumber":285,"sourceCode":"        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) {\n        return ipAddressToUrlString(address) + ':' + port;\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.","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/NetUtils.java#L267-L303","documentation":"NetUtils.ipAddressToUrlString handles exactly Inet4Address and Inet6Address; any other InetAddress subclass triggers IllegalArgumentException with the object printed. The JDK only produces those two in practice, so this guard fires almost exclusively on custom InetAddress subclasses passed by user code.","triggerScenarios":"Passing a hand-written InetAddress subclass (e.g. a mock in tests or a custom InetAddr implementation overriding getAddress) into ipAddressToUrlString or ipAddressAndPortToUrlString.","commonSituations":"Unit tests stubbing InetAddress with Mockito/Spy subclasses; exotic JVMs or libraries introducing non-standard address types; copying addresses between frameworks that wrap them.","solutions":["Convert the custom object to a real address first: InetAddress.getByName(custom.getHostName()) or InetAddress.getByAddress(custom.getAddress()).","In tests, mock with concrete Inet4Address/Inet6Address instances (e.g. InetAddress.getByName(\"127.0.0.1\")) instead of subclass mocks."],"exampleFix":"// before\nNetUtils.ipAddressToUrlString(mockAddr); // mockAddr extends InetAddress\n\n// after\nInetAddress real = InetAddress.getByAddress(mockAddr.getAddress());\nNetUtils.ipAddressToUrlString(real);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isSupportedInetAddress(InetAddress a) { return a instanceof Inet4Address || a instanceof Inet6Address; }","tryCatchPattern":"if (!(addr instanceof Inet4Address) && !(addr instanceof Inet6Address)) { addr = InetAddress.getByAddress(addr.getAddress()); } // normalize before use","preventionTips":["In tests, use real Inet4Address/Inet6Address instances, not subclass mocks.","Convert foreign address types via getByAddress before Flink APIs."],"tags":["network","testing","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}