{"record":{"id":"6317061cb5c699a0","repo":"dotnet/aspnetcore","slug":"a-valid-url-is-required","errorCode":null,"errorMessage":"A valid url is required.","messagePattern":"A valid url is required\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java","lineNumber":128,"sourceCode":"        }\n        return null;\n    }\n\n    // For testing purposes\n    void setTickRate(long tickRateInMilliseconds) {\n        this.tickRate = tickRateInMilliseconds;\n    }\n\n    // For testing purposes\n    Transport getTransport() {\n        return this.state.getConnectionState().transport;\n    }\n\n    HubConnection(String url, Transport transport, boolean skipNegotiate, HttpClient httpClient, HubProtocol protocol,\n                  Single<String> accessTokenProvider, long handshakeResponseTimeout, Map<String, String> headers, TransportEnum transportEnum,\n                  Action1<OkHttpClient.Builder> configureBuilder, long serverTimeout, long keepAliveInterval) {\n        if (url == null || url.isEmpty()) {\n            throw new IllegalArgumentException(\"A valid url is required.\");\n        }\n\n        this.state = new ReconnectingConnectionState(this.logger);\n        this.baseUrl = url;\n        this.protocol = protocol;\n\n        if (accessTokenProvider != null) {\n            this.accessTokenProvider = accessTokenProvider;\n        } else {\n            this.accessTokenProvider = Single.just(\"\");\n        }\n\n        if (httpClient != null) {\n            this.httpClient = httpClient;\n        } else {\n            this.httpClient = new DefaultHttpClient(configureBuilder);\n        }\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java#L110-L146","documentation":"Thrown by the HubConnection constructor when url is null or empty. This is the package-private constructor invoked by HubConnectionBuilder; users typically hit it through the builder if they somehow bypass withUrl, or when constructing HubConnection directly in tests. Distinct from setBaseUrl (175) which is the post-construction setter.","triggerScenarios":"HubConnection is constructed (directly or via a builder path) with url == null or url.isEmpty(). In normal builder usage withUrl guards this earlier (162), so this throw surfaces for direct constructor use, custom builders, or reflection-based test helpers.","commonSituations":"Tests that new HubConnection(...) directly with a null url; a custom builder/wrapper that forgets to set the url; a configuration load that returns null and the wrapper passes it straight through.","solutions":["Always build HubConnection via HubConnectionBuilder.create(url) so withUrl/withUrl validation runs first.","Null-check the url at the configuration boundary and fail with a clearer message before reaching the constructor.","In tests, pass a dummy URL (http://localhost:0) rather than null."],"exampleFix":"// before (test)\nHubConnection conn = new HubConnection(null, transport, ...); // throws\n\n// after\nHubConnection conn = HubConnectionBuilder.create(\"http://localhost:5050/hub\").build();","handlingStrategy":"validation","validationCode":"HubConnection build(String url) {\n  if (url == null || url.isEmpty()) {\n    throw new IllegalArgumentException(\"hub url is required\");\n  }\n  return HubConnectionBuilder.create(url).build();\n}","typeGuard":"boolean isValidHubUrl(String url) {\n  return url != null && !url.isEmpty();\n}","tryCatchPattern":"try {\n  return HubConnectionBuilder.create(url).build();\n} catch (IllegalArgumentException e) {\n  if (\"A valid url is required.\".equals(e.getMessage())) {\n    // supply a valid url and rebuild\n  } else throw e;\n}","preventionTips":["Always build through HubConnectionBuilder.create(url).","Validate the URL at the configuration boundary before constructing.","In tests pass a dummy URL rather than null."],"tags":["signalr","java","argument-validation","url","constructor"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}