{"record":{"id":"7348329e4eea4dd3","repo":"apache/flink","slug":"the-given-host-port-doesn-t-contain-a-valid","errorCode":null,"errorMessage":"The given host:port ('{}') doesn't contain a valid host","messagePattern":"The given host:port \\('(.+?)'\\) doesn't contain a valid host","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/NetUtils.java","lineNumber":116,"sourceCode":"     * <p>Works also for ipv6.\n     *\n     * <p>See:\n     * http://stackoverflow.com/questions/2345063/java-common-way-to-validate-and-convert-hostport-to-inetsocketaddress\n     *\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","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/NetUtils.java#L98-L134","documentation":"NetUtils.validateHostPortString parses a 'host:port' string by constructing a java.net.URL (prefixing 'http://' if no scheme is present) and rejects it when the resulting URL has a null host. It is the strict validation behind Flink APIs that accept a single host:port string. The message echoes the offending input so the misconfigured value is visible in the log.","triggerScenarios":"Passing a string that URL-parses but carries no host, e.g. 'http:///path', ':8081', or a URL whose authority is empty, to NetUtils host:port parsing (validateHostPortString callers such as the hostPort-parsing utilities used by client/REST address configs).","commonSituations":"jobmanager.rpc.address / rest.address style configs assembled from variables that come out empty; a service-discovery endpoint returning 'http://' + '' + ':8081'; hand-built strings where the host placeholder was never substituted.","solutions":["Check the echoed value in the message and find which config option/variable produced an empty host.","Fix the string so it is 'host:port' (e.g. 'localhost:8081') or a full 'http://host:port' URL.","If the host comes from an environment variable or template, assert it is non-empty before building the hostPort string."],"exampleFix":"// before\nString hostPort = \"http://\" + hostVar + \":8081\"; // hostVar was \"\"\n\n// after\nPreconditions.checkArgument(!hostVar.isEmpty(), \"host must be set\");\nString hostPort = \"http://\" + hostVar + \":8081\";","handlingStrategy":"validation","validationCode":"// before calling a host:port API\nstatic boolean hasHostPort(String s) {\n    try {\n        java.net.URL u = new java.net.URL(s.startsWith(\"http\") ? s : \"http://\" + s);\n        return u.getHost() != null && !u.getHost().isEmpty();\n    } catch (java.net.MalformedURLException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) { if (e.getMessage().contains(\"valid host\")) { /* fix config, fail fast with context */ } throw e; }","preventionTips":["Validate assembled host:port strings in config-loading code.","Never concatenate scheme + host + port when any component may be empty."],"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"}