{"record":{"id":"15ba8ddc5499e4d0","repo":"dotnet/aspnetcore","slug":"the-hubconnection-url-must-be-a-valid-url-15ba8d","errorCode":null,"errorMessage":"The HubConnection url must be a valid url.","messagePattern":"The HubConnection url must be a valid url\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java","lineNumber":215,"sourceCode":"     *\n     * @return HubConnection state enum.\n     */\n    public HubConnectionState getConnectionState() {\n        return this.state.getHubConnectionState();\n    }\n\n    // For testing only\n    String getBaseUrl() {\n        return this.baseUrl;\n    }\n\n    /**\n     * Sets a new url for the HubConnection.\n     * @param url The url to connect to.\n     */\n    public void setBaseUrl(String url) {\n        if (url == null || url.isEmpty()) {\n            throw new IllegalArgumentException(\"The HubConnection url must be a valid url.\");\n        }\n\n        if (this.state.getHubConnectionState() != HubConnectionState.DISCONNECTED) {\n            throw new IllegalStateException(\"The HubConnection must be in the disconnected state to change the url.\");\n        }\n\n        this.baseUrl = url;\n    }\n\n    /**\n     * Starts a connection to the server.\n     *\n     * @return A Completable that completes when the connection has been established.\n     */\n    public Completable start() {\n        CompletableSubject localStart = CompletableSubject.create();\n\n        this.state.lock.lock();","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java#L197-L233","documentation":"An IllegalArgumentException thrown by setBaseUrl when the provided url is null or empty. setBaseUrl is used to repoint an existing HubConnection at a different endpoint (commonly after a redirect or for reconnection), and it guards input validity before mutating baseUrl.","triggerScenarios":"Calling hubConnection.setBaseUrl(null) or setBaseUrl(\"\") at runtime, often when feeding a URL sourced from a dynamic config or a failed redirect parse that resolves to null/empty.","commonSituations":"A redirect URL or load-balancer-injected endpoint resolves to null because the response field was absent. A configuration reload yields a blank value. Code that conditionally builds the new URL and passes it without a null check.","solutions":["Validate the new URL is non-null and non-empty before calling setBaseUrl, and log/skip if invalid.","Fix the upstream source of the URL (redirect response parsing, config provider) so it yields a real value.","Guard against null at the call site and fall back to the existing baseUrl."],"exampleFix":"// before\nconnection.setBaseUrl(redirectResponse.getNewUrl()); // null if field absent\n\n// after\nString newUrl = redirectResponse.getNewUrl();\nif (newUrl != null && !newUrl.isEmpty()) {\n    connection.setBaseUrl(newUrl);\n}","handlingStrategy":"validation","validationCode":"String newUrl = computeRedirectUrl();\nif (newUrl == null || newUrl.isEmpty()) {\n    logger.warn(\"Ignoring empty redirect URL; keeping current base URL\");\n} else {\n    connection.setBaseUrl(newUrl);\n}","typeGuard":null,"tryCatchPattern":"try {\n    connection.setBaseUrl(newUrl);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"valid url\")) {\n        logger.error(\"Refusing to set empty base URL\", e);\n    } else { throw e; }\n}","preventionTips":["Never pass user/remote-supplied URLs to setBaseUrl without a null/empty check.","Log the source of dynamically-computed URLs to trace blank values back to their origin.","Keep the current baseUrl as the fallback when a candidate replacement is invalid."],"tags":["signalr","java","configuration","validation","url"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}