{"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/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java#L110-L146","documentation":"An IllegalArgumentException thrown by the HubConnection constructor when the url argument is null or empty. The connection requires a non-null, non-empty endpoint to negotiate and establish a transport, so construction fails immediately rather than deferring the failure to start(). This is the earliest validation point in the HubConnectionBuilder pipeline.","triggerScenarios":"Calling HubConnectionBuilder.create(null), HubConnectionBuilder.create(\"\"), or building a URL string that resolves to null/empty (e.g. a misconfigured property or environment variable that yields null) and passing it to the builder.","commonSituations":"Configuration property for the SignalR endpoint is missing or unset in application.properties/yaml, so the injected value is null. A dynamically constructed URL where a required component (host, path) is null causing the whole concatenation to be null or empty. Using the builder before the URL is known (e.g. during early init).","solutions":["Provide a non-empty, valid URL string to HubConnectionBuilder.create(url).","Validate the URL is non-null and non-empty before building the HubConnection, failing config loading early with a clear message.","Check that the configuration source (env var, properties file) actually defines the endpoint value."],"exampleFix":"// before\nString endpoint = config.get(\"signalr.url\"); // null if missing\nHubConnection connection = HubConnectionBuilder.create(endpoint).build();\n\n// after\nString endpoint = config.get(\"signalr.url\");\nif (endpoint == null || endpoint.isEmpty()) {\n    throw new IllegalStateException(\"signalr.url must be configured\");\n}\nHubConnection connection = HubConnectionBuilder.create(endpoint).build();","handlingStrategy":"validation","validationCode":"String url = config.get(\"signalr.url\");\nif (url == null || url.isEmpty()) {\n    throw new IllegalStateException(\"Missing signalr.url configuration\");\n}\n// Optionally validate URL format\ntry { new java.net.URL(url); } catch (Exception e) { throw new IllegalArgumentException(\"Invalid signalr.url: \" + url); }\nHubConnection conn = HubConnectionBuilder.create(url).build();","typeGuard":null,"tryCatchPattern":"try {\n    HubConnection conn = HubConnectionBuilder.create(url).build();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"valid url\")) {\n        // handle missing configuration\n    }\n    throw e;\n}","preventionTips":["Centralize SignalR endpoint configuration and validate it at app startup before building the HubConnection.","Use strongly-typed config properties (@Value/@ConfigProperty with defaults) so missing values fail fast elsewhere.","Add a unit test that constructs the builder with the production config to catch null/empty URLs in CI."],"tags":["signalr","java","configuration","validation","constructor"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}