{"record":{"id":"ae511eff971c6e42","repo":"apache/flink","slug":"could-not-parse-url-from-url","errorCode":null,"errorMessage":"Could not parse URL from {url}","messagePattern":"Could not parse URL from (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-clients/src/main/java/org/apache/flink/client/program/rest/RestClusterClient.java","lineNumber":1202,"sourceCode":"                        .orElse(false);\n    }\n\n    @VisibleForTesting\n    CompletableFuture<URL> getWebMonitorBaseUrl() {\n        return FutureUtils.orTimeout(\n                        webMonitorLeaderRetriever.getLeaderFuture(),\n                        restClusterClientConfiguration.getAwaitLeaderTimeout(),\n                        TimeUnit.MILLISECONDS,\n                        String.format(\n                                \"Waiting for leader address of WebMonitorEndpoint timed out after %d ms.\",\n                                restClusterClientConfiguration.getAwaitLeaderTimeout()))\n                .thenApplyAsync(\n                        leaderAddressSessionId -> {\n                            final String url = leaderAddressSessionId.f0;\n                            try {\n                                return new URL(url);\n                            } catch (MalformedURLException e) {\n                                throw new IllegalArgumentException(\n                                        \"Could not parse URL from \" + url, e);\n                            }\n                        },\n                        executorService);\n    }\n}\n","sourceCodeStart":1184,"sourceCodeEnd":1209,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/rest/RestClusterClient.java#L1184-L1209","documentation":"Thrown as an IllegalArgumentException when the leader address retrieved from the WebMonitorEndpoint leader retriever cannot be parsed as a valid java.net.URL. The leader address (a string) is expected to be a well-formed URL (e.g., http://host:8081). If it is malformed (missing scheme, invalid characters, or null), MalformedURLException is caught and wrapped.","triggerScenarios":"Calling getWebMonitorBaseUrl() during RestClusterClient initialization when the discovered leader address is not a valid URL — e.g., the leader address is a bare hostname without a scheme, contains invalid characters, or is null.","commonSituations":"ZooKeeper or Kubernetes leader election returns a leader address without an http:// or https:// scheme; misconfigured rest.address or rest.port in flink-conf.yaml; leader address contains whitespace or special characters; network discovery returns an incomplete address.","solutions":["Check flink-conf.yaml: ensure rest.address and rest.port are set correctly and the address is a valid hostname or IP.","If using Zookeeper/K8s HA, verify the leader election service returns a fully-qualified URL (including scheme).","Inspect the leader address in ZooKeeper (znode data) or K8s configmap for format correctness.","Ensure the rest.bind-port and rest.address are accessible from the client."],"exampleFix":"# flink-conf.yaml — before\nrest.address: myhost\n# after — include scheme is not needed but ensure address is valid\nrest.address: myhost\nrest.port: 8081\n# Verify leader URL manually:\n# echo \"conf\" | nc <jm-host> <rest-port> | grep rest.address","handlingStrategy":"validation","validationCode":"// Validate leader address format before constructing client\nString leaderAddress = retrieveLeaderAddress(); // from ZK or K8s\ntry {\n    new URL(leaderAddress);\n} catch (MalformedURLException e) {\n    // prepend http:// if missing scheme\n    if (!leaderAddress.startsWith(\"http\")) {\n        leaderAddress = \"http://\" + leaderAddress;\n    }\n    new URL(leaderAddress); // re-validate\n}","typeGuard":null,"tryCatchPattern":"try {\n    URL baseUrl = client.getWebMonitorBaseUrl().get();\n} catch (ExecutionException e) {\n    Throwable cause = ExceptionUtils.stripExecutionException(e);\n    if (cause instanceof IllegalArgumentException && cause.getMessage().contains(\"Could not parse URL\")) {\n        // leader address is malformed — check rest.address/rest.port in flink-conf.yaml\n    }\n}","preventionTips":["Ensure rest.address in flink-conf.yaml is a valid hostname or IP.","Verify leader election (ZK/K8s) returns a fully-qualified URL.","Check for whitespace or encoding issues in the leader address."],"tags":["rest-client","leader-election","url-parsing","configuration"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}