{"record":{"id":"1b66f7d30f45110b","repo":"HMCL-dev/HMCL","slug":"invalid-server-address-address","errorCode":null,"errorMessage":"Invalid server address: ${address}","messagePattern":"Invalid server address: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/util/ServerAddress.java","lineNumber":45,"sourceCode":"public record ServerAddress(String host, int port) {\n\n    private static final int UNKNOWN_PORT = -1;\n\n    private static IllegalArgumentException illegalAddress(String address) {\n        return new IllegalArgumentException(\"Invalid server address: \" + address);\n    }\n\n    /**\n     * @throws IllegalArgumentException if the address is not a valid server address\n     */\n    public static @NotNull ServerAddress parse(@NotNull String address) {\n        Objects.requireNonNull(address);\n\n        if (!address.startsWith(\"[\")) {\n            int colonPos = address.indexOf(':');\n            if (colonPos >= 0) {\n                if (colonPos == address.length() - 1)\n                    throw illegalAddress(address);\n\n                String host = address.substring(0, colonPos);\n                int port;\n                try {\n                    port = Integer.parseInt(address.substring(colonPos + 1));\n                } catch (NumberFormatException e) {\n                    throw illegalAddress(address);\n                }\n                if (port < 0 || port > 0xFFFF)\n                    throw illegalAddress(address);\n                return new ServerAddress(host, port);\n            } else {\n                return new ServerAddress(address);\n            }\n        } else {\n            // Parse IPv6 address\n            int colonIndex = address.indexOf(':');\n            int closeBracketIndex = address.lastIndexOf(']');","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/util/ServerAddress.java#L27-L63","documentation":"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>\").","triggerScenarios":"ServerAddress.parse(\"host:\") — an address ending in ':' with nothing after it, while not using bracketed IPv6 syntax.","commonSituations":"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.","solutions":["Provide a port after the colon (e.g. 'mc.example.com:25565').","If no port is intended, remove the trailing colon entirely (e.g. 'mc.example.com').","Trim/normalize the address string before parsing."],"exampleFix":"// before\nServerAddress.parse(\"mc.example.com:\")\n// after\nServerAddress.parse(\"mc.example.com:25565\")","handlingStrategy":"validation","validationCode":"boolean isValidServerAddress(String address) {\n    if (address == null || address.isEmpty()) return false;\n    if (address.startsWith(\"[\")) return true; // IPv6 branch, validated separately\n    int colon = address.indexOf(':');\n    if (colon < 0) return true; // host only\n    return colon < address.length() - 1 && address.substring(colon + 1).chars().allMatch(Character::isDigit);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ServerAddress addr = ServerAddress.parse(input);\n} catch (IllegalArgumentException e) {\n    showError(\"Server address must be host, host:port, or [ipv6]:port\");\n}","preventionTips":["Never leave a trailing ':' without a port; either add the port or drop the colon.","Trim whitespace from user-entered addresses.","Normalize config values at load time before parsing."],"tags":["server-address","parsing","java","minecraft"],"backgroundTag":"invalid-server-address","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}