{"record":{"id":"c67dbf5e9e88d73b","repo":"apache/flink","slug":"hostport-should-not-be-null-or-empty","errorCode":null,"errorMessage":"hostPort should not be null or empty","messagePattern":"hostPort should not be null or empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/util/NetUtils.java","lineNumber":107,"sourceCode":"     */\n    public static InetSocketAddress parseHostPortAddress(String hostPort) {\n        URL url = validateHostPortString(hostPort);\n        return new InetSocketAddress(url.getHost(), url.getPort());\n    }\n\n    /**\n     * Validates if the given String represents a hostname:port.\n     *\n     * <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(","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/util/NetUtils.java#L89-L125","documentation":"NetUtils.parseHostnamePort validates a 'host:port' string by internally constructing a URL (prepending http:// when no scheme exists) and inspecting host/port. The first guard rejects null, empty, or whitespace-only input with IllegalArgumentException, since no host:port can be parsed from it.","triggerScenarios":"Calling NetUtils.parseHostnamePort(s) with s null, empty, or whitespace — e.g. an address option that was never set, a trimmed-to-empty env var, or a list entry that is a blank string.","commonSituations":"REST/JobManager address configuration (e.g. 'host:port' style options) missing from flink-conf; environment variables like JOBMANAGER_HOST expanded to empty in containers; string splitting producing empty tokens from trailing commas ('a:1,b:2,').","solutions":["Provide a non-empty host:port value in the configuration entry named in your setup code.","Filter blank entries before parsing comma-separated address lists: Arrays.stream(list).filter(s -> !s.isBlank()).","Guard nullable sources with a default address or a fail-fast message naming the missing option.","Trim input and validate format (matches 'host:port' with numeric port) before calling parseHostnamePort."],"exampleFix":"// before\nInetSocketAddress addr = NetUtils.parseHostnamePort(System.getenv(\"JM_ADDRESS\")); // env unset -> IAE\n\n// after\nString address = System.getenv(\"JM_ADDRESS\");\nif (address == null || address.isBlank()) {\n    address = \"localhost:8081\"; // or throw with a clear message\n}\nInetSocketAddress addr = NetUtils.parseHostnamePort(address);","handlingStrategy":"validation","validationCode":"if (hostPort == null || hostPort.isBlank()) {\n    throw new IllegalArgumentException(\"host:port must be non-empty (check address config/env var)\");\n}\nInetSocketAddress addr = NetUtils.parseHostnamePort(hostPort);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter blank tokens when parsing comma-separated address lists","Validate 'host:port' format (numeric port) at config load","Provide defaults or fail fast when address env vars are unset in containers"],"tags":["network","address","validation","configuration"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}