{"record":{"id":"08cec05b7e97e282","repo":"apache/flink","slug":"the-given-host-port-is-invalid","errorCode":null,"errorMessage":"The given host:port ('{}') is invalid","messagePattern":"The given host:port \\('(.+?)'\\) is invalid","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/NetUtils.java","lineNumber":125,"sourceCode":"            throw new IllegalArgumentException(\"hostPort should not be null or empty\");\n        }\n        try {\n            URL u =\n                    (hostPort.toLowerCase().startsWith(\"http://\")\n                                    || hostPort.toLowerCase().startsWith(\"https://\"))\n                            ? new URL(hostPort)\n                            : new URL(\"http://\" + hostPort);\n            if (u.getHost() == null) {\n                throw new IllegalArgumentException(\n                        \"The given host:port ('\" + hostPort + \"') doesn't contain a valid host\");\n            }\n            if (u.getPort() == -1) {\n                throw new IllegalArgumentException(\n                        \"The given host:port ('\" + hostPort + \"') doesn't contain a valid port\");\n            }\n            return u;\n        } catch (MalformedURLException e) {\n            throw new IllegalArgumentException(\n                    \"The given host:port ('\" + hostPort + \"') is invalid\", e);\n        }\n    }\n\n    /**\n     * Converts an InetSocketAddress to a URL. This method assigns the \"http://\" schema to the URL\n     * by default.\n     *\n     * @param socketAddress the InetSocketAddress to be converted\n     * @return a URL object representing the provided socket address with \"http://\" schema\n     */\n    public static URL socketToUrl(InetSocketAddress socketAddress) {\n        String hostString = socketAddress.getHostString();\n        // If the hostString is an IPv6 address, it needs to be enclosed in square brackets\n        // at the beginning and end.\n        if (socketAddress.getAddress() != null\n                && socketAddress.getAddress() instanceof Inet6Address\n                && hostString.equals(socketAddress.getAddress().getHostAddress())) {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/NetUtils.java#L107-L143","documentation":"This IllegalArgumentException wraps a java.net.MalformedURLException raised while NetUtils.validateHostPortString turns the input into a URL. It means the string is not parseable as a URL at all — malformed syntax rather than merely a missing host or port. The original MalformedURLException is attached as the cause for details.","triggerScenarios":"Inputs like 'host:8081:extra', an unbracketed IPv6 literal such as 'fe80::1:8081', 'http://host:NotAPort', or strings containing illegal URL characters (spaces, stray slashes) passed to host:port validation.","commonSituations":"IPv6 addresses used without square brackets; copy-pasted endpoints with trailing paths or whitespace; interpolating a full URL into a field that already gets the 'http://' prefix, producing 'http://http://host:port'.","solutions":["Read the cause (MalformedURLException) to see where parsing failed.","For IPv6, bracket the address: 'http://[fe80::1]:8081' or '[fe80::1]:8081'.","Trim whitespace and remove duplicate schemes or stray path/query suffixes from the value.","If the field expects bare host:port, do not also include a scheme that conflicts with the auto-prepended one."],"exampleFix":"// before\nString address = \"fe80::1:8081\"; // ambiguous IPv6\n\n// after\nString address = \"[fe80::1]:8081\";","handlingStrategy":"try-catch","validationCode":"static boolean isParsableHostPort(String s) {\n    try { new java.net.URL(s.startsWith(\"http\") ? s : \"http://\" + s); return true; }\n    catch (java.net.MalformedURLException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { NetUtils-validating call } catch (IllegalArgumentException e) { Throwable cause = e.getCause(); if (cause instanceof MalformedURLException) { /* report malformed value, keep cause */ } }","preventionTips":["Bracket IPv6 literals in endpoints: [fe80::1]:8081.","Trim and sanity-check endpoint strings from user input before passing them on."],"tags":["network","url-parsing","ipv6","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}