HMCL-dev/HMCL · error · IllegalArgumentException

Invalid server address

Error message

Invalid server address: ${address}

What it means

ServerAddress.parse rejects addresses where a non-bracketed host contains a trailing ':' with no port (e.g. 'mc.example.com:'). Such a string cannot be split into host and a valid numeric port, so illegalAddress(address) throws IllegalArgumentException("Invalid server address: <address>").

Solutions

  1. Provide a port after the colon (e.g. 'mc.example.com:25565').
  2. If no port is intended, remove the trailing colon entirely (e.g. 'mc.example.com').
  3. Trim/normalize the address string before parsing.

Example fix

// before
ServerAddress.parse("mc.example.com:")
// after
ServerAddress.parse("mc.example.com:25565")
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidServerAddress(String address) {
    if (address == null || address.isEmpty()) return false;
    if (address.startsWith("[")) return true; // IPv6 branch, validated separately
    int colon = address.indexOf(':');
    if (colon < 0) return true; // host only
    return colon < address.length() - 1 && address.substring(colon + 1).chars().allMatch(Character::isDigit);
}

Try / catch

try {
    ServerAddress addr = ServerAddress.parse(input);
} catch (IllegalArgumentException e) {
    showError("Server address must be host, host:port, or [ipv6]:port");
}

Prevention

When it happens

Trigger: ServerAddress.parse("host:") — an address ending in ':' with nothing after it, while not using bracketed IPv6 syntax.

Common situations: Server entries in launcher config with the port deleted but the colon left behind; template expansion producing empty port fields; users typing 'host:' expecting a default port.

Related errors


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

Appendix: source

Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/util/ServerAddress.java:45

public record ServerAddress(String host, int port) {

    private static final int UNKNOWN_PORT = -1;

    private static IllegalArgumentException illegalAddress(String address) {
        return new IllegalArgumentException("Invalid server address: " + address);
    }

    /**
     * @throws IllegalArgumentException if the address is not a valid server address
     */
    public static @NotNull ServerAddress parse(@NotNull String address) {
        Objects.requireNonNull(address);

        if (!address.startsWith("[")) {
            int colonPos = address.indexOf(':');
            if (colonPos >= 0) {
                if (colonPos == address.length() - 1)
                    throw illegalAddress(address);

                String host = address.substring(0, colonPos);
                int port;
                try {
                    port = Integer.parseInt(address.substring(colonPos + 1));
                } catch (NumberFormatException e) {
                    throw illegalAddress(address);
                }
                if (port < 0 || port > 0xFFFF)
                    throw illegalAddress(address);
                return new ServerAddress(host, port);
            } else {
                return new ServerAddress(address);
            }
        } else {
            // Parse IPv6 address
            int colonIndex = address.indexOf(':');
            int closeBracketIndex = address.lastIndexOf(']');

View on GitHub (pinned to 24702dc5a0)