{"record":{"id":"b7e4416b45c1436f","repo":"apache/flink","slug":"the-given-host-port-doesn-t-contain-a-valid-b7e441","errorCode":null,"errorMessage":"The given host:port ('{}') doesn't contain a valid port","messagePattern":"The given host:port \\('(.+?)'\\) doesn't contain a valid port","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/NetUtils.java","lineNumber":120,"sourceCode":"     *\n     * @return URL object for accessing host and port\n     */\n    private static URL validateHostPortString(String hostPort) {\n        if (StringUtils.isNullOrWhitespaceOnly(hostPort)) {\n            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();","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/NetUtils.java#L102-L138","documentation":"After NetUtils.validateHostPortString successfully builds a URL, it requires an explicit port: URL.getPort() == -1 means no ':port' was present in the authority. A host-only string like 'localhost' is therefore rejected even though it is a valid host, because the Flink APIs using this validation need a concrete endpoint. The message includes the offending input.","triggerScenarios":"Calling a host:port-parsing API with 'myhost', 'http://myhost' (no port), or a port that is not numeric so the URL treats the suffix as part of the path/authority without a port.","commonSituations":"Configuring a REST/RPC address with a hostname only; YAML placeholders like ${HOST} where the ':${PORT}' suffix was dropped; passing 'jobmanager.rpc.address' value where a port was expected alongside it.","solutions":["Append the port to the string: 'myhost:8081' instead of 'myhost'.","If a default port applies, add it when building the string rather than relying on Flink to assume one.","Verify no typo swallowed the port (e.g. 'myhost::8081' or 'myhost 8081')."],"exampleFix":"// before\nString address = \"jobmanager.host\"; // no port\n\n// after\nString address = \"jobmanager.host:6123\";","handlingStrategy":"validation","validationCode":"static void requireHostAndPort(String hostPort) {\n    String s = hostPort.replaceFirst(\"^https?://\", \"\");\n    int i = s.lastIndexOf(':');\n    Preconditions.checkArgument(i > 0, \"missing port in %s\", hostPort);\n    Preconditions.checkArgument(s.substring(i + 1).chars().allMatch(Character::isDigit),\n            \"port not numeric in %s\", hostPort);\n}","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) { log.error(\"endpoint {} lacks a port; expected host:port\", value, e); throw e; }","preventionTips":["Always build endpoints as host + ':' + port in one place.","Unit-test config builders so a missing port fails in CI, not in production."],"tags":["network","configuration","url-parsing","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}