dotnet/aspnetcore · error · IllegalArgumentException

A valid url is required.

Error message

A valid url is required.

What it means

HubConnectionBuilder.create(url) is the entry point for building a connection. It rejects a null or empty URL string with IllegalArgumentException immediately, before constructing the HttpHubConnectionBuilder. This is a fail-fast precondition on the builder.

Solutions

  1. Validate the URL at application startup: Objects.requireNonNull(url) and url.trim().isEmpty() checks with a clear config error.
  2. Provide a sensible default or fail application bootstrap if the URL property is missing.
  3. Log the source of the URL (env var name, property key) so the misconfiguration is obvious.

Example fix

// before
String url = System.getenv("HUB_URL"); // null if unset
HubConnectionBuilder.create(url);

// after
String url = System.getenv("HUB_URL");
if (url == null || url.trim().isEmpty()) {
    throw new IllegalStateException("HUB_URL env var must be set");
}
HubConnectionBuilder.create(url.trim());
Defensive patterns

Strategy: validation

Validate before calling

String url = loadHubUrl();
if (url == null || url.trim().isEmpty()) {
  throw new IllegalStateException(
    "hub URL is missing (check HUB_URL / config)");
}
HubConnectionBuilder.create(url.trim());

Prevention

When it happens

Trigger: Passing null (e.g. from an unset config/properties value) or an empty string (misconfigured env var, blank property) to HubConnectionBuilder.create().

Common situations: Reading the hub URL from an environment variable or config file that was not set; string trimming producing empty; typo in property key; dependency injection providing null before configuration is loaded.

Related errors


AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11). Data as JSON: /api/errors/c3083ee8fcb81dd8. Report an issue: GitHub.

Appendix: source

Thrown at src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/HubConnectionBuilder.java:18

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

package com.microsoft.signalr;

/**
 * A builder for configuring {@link HubConnection} instances.
 */
public abstract class HubConnectionBuilder {
    /**
     * Creates a new instance of {@link HttpHubConnectionBuilder}.
     *
     * @param url The URL of the SignalR hub to connect to.
     * @return An instance of {@link HttpHubConnectionBuilder}.
     */
    public static HttpHubConnectionBuilder create(String url) {
        if (url == null || url.isEmpty()) {
            throw new IllegalArgumentException("A valid url is required.");
        }
        return new HttpHubConnectionBuilder(url);
    }

    /**
     * Builds a new instance of {@link HubConnection}.
     *
     * @return A new instance of {@link HubConnection}.
     */
    public abstract HubConnection build();
}

View on GitHub (pinned to 3600ca084e)