dotnet/aspnetcore · error · IllegalArgumentException
The HubConnection url must be a valid url.
Error message
The HubConnection url must be a valid url.
What it means
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.
Source
Thrown at src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnection.java:215
*
* @return HubConnection state enum.
*/
public HubConnectionState getConnectionState() {
return this.state.getHubConnectionState();
}
// For testing only
String getBaseUrl() {
return this.baseUrl;
}
/**
* Sets a new url for the HubConnection.
* @param url The url to connect to.
*/
public void setBaseUrl(String url) {
if (url == null || url.isEmpty()) {
throw new IllegalArgumentException("The HubConnection url must be a valid url.");
}
if (this.state.getHubConnectionState() != HubConnectionState.DISCONNECTED) {
throw new IllegalStateException("The HubConnection must be in the disconnected state to change the url.");
}
this.baseUrl = url;
}
/**
* Starts a connection to the server.
*
* @return A Completable that completes when the connection has been established.
*/
public Completable start() {
CompletableSubject localStart = CompletableSubject.create();
this.state.lock.lock();View on GitHub (pinned to 294cab2f9b)
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.
Example fix
// before
connection.setBaseUrl(redirectResponse.getNewUrl()); // null if field absent
// after
String newUrl = redirectResponse.getNewUrl();
if (newUrl != null && !newUrl.isEmpty()) {
connection.setBaseUrl(newUrl);
} Defensive patterns
Strategy: validation
Validate before calling
String newUrl = computeRedirectUrl();
if (newUrl == null || newUrl.isEmpty()) {
logger.warn("Ignoring empty redirect URL; keeping current base URL");
} else {
connection.setBaseUrl(newUrl);
} Try / catch
try {
connection.setBaseUrl(newUrl);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("valid url")) {
logger.error("Refusing to set empty base URL", e);
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- A valid url is required.
- A valid url is required.
- The HubConnection url must be a valid url.
- The 'HubConnectionBuilder.withUrl' method must be called bef
- '%s' already has a value returning handler. Multiple return
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/15ba8ddc5499e4d0.
Report an issue: GitHub.