HMCL-dev/HMCL · error · IllegalArgumentException

Host cannot be blank

Error message

Host cannot be blank

What it means

Compact-constructor guard on the Http proxy record: a blank host string is rejected at construction because an HTTP proxy without a host is meaningless. This is a generic argument validation, not tied to a specific input source.

Solutions

  1. Supply a non-blank host string (hostname or IP) when constructing Http
  2. Fix the saved settings file so proxy.host is populated
  3. Disable proxy mode in settings if no proxy is needed

Example fix

// before
new ProxyOption.Http("", 8080, null, null)
// after
new ProxyOption.Http("127.0.0.1", 8080, null, null)
Defensive patterns

Strategy: validation

Validate before calling

if (host == null || host.isBlank())
    throw new IllegalArgumentException("Proxy host must be set before enabling proxy");

Type guard

static boolean validHttpProxy(String host, int port) {
    return host != null && !host.isBlank() && port >= 0 && port <= 0xFFFF;
}

Try / catch

try {
    option = new ProxyOption.Http(host, port, user, pass);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("Host cannot be blank")) {
        // prompt user for host or disable proxy
    } else throw e;
}

Prevention

When it happens

Trigger: Calling new ProxyOption.Http(null/""/" ", port, ...) or deserializing a settings JSON with an empty proxy host into an Http record.

Common situations: User enabled 'use proxy' in launcher settings but left the host field empty, config migration lost the host value.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10). Data as JSON: /api/errors/ef0199ea8a3b24dc. Report an issue: GitHub.

Appendix: source

Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/game/ProxyOption.java:44

record Http(@NotNull String host, int port, @Nullable String username,
            @Nullable String password) implements ProxyOption {
    public Http {
        if (StringUtils.isBlank(host)) {
            throw new IllegalArgumentException("Host cannot be blank");
        }
        if (port < 0 || port > 0xFFFF) {
            throw new IllegalArgumentException("Illegal port: " + port);
        }
    }
}

View on GitHub (pinned to 24702dc5a0)