{"record":{"id":"dc7bd414c7ae5073","repo":"prestodb/presto","slug":"port-is-invalid","errorCode":null,"errorMessage":"Port is invalid: ","messagePattern":"Port is invalid: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java","lineNumber":151,"sourceCode":"    {\n        return hasPort() ? port : defaultPort;\n    }\n\n    /**\n     * Build a HostAddress instance from separate host and port values.\n     * <p>\n     * <p>Note: Non-bracketed IPv6 literals are allowed.\n     *\n     * @param host the host string to parse.  Must not contain a port number.\n     * @param port a port number from [0..65535]\n     * @return if parsing was successful, a populated HostAddress object.\n     * @throws IllegalArgumentException if {@code host} contains a port number,\n     * or {@code port} is out of range.\n     */\n    public static HostAddress fromParts(String host, int port)\n    {\n        if (!isValidPort(port)) {\n            throw new IllegalArgumentException(\"Port is invalid: \" + port);\n        }\n        HostAddress parsedHost = fromString(host);\n        if (parsedHost.hasPort()) {\n            throw new IllegalArgumentException(\"host contains a port declaration: \" + host);\n        }\n        return new HostAddress(parsedHost.host, port);\n    }\n\n    private static final Pattern BRACKET_PATTERN = Pattern.compile(\"^\\\\[(.*:.*)\\\\](?::(\\\\d*))?$\");\n\n    /**\n     * Split a freeform string into a host and port, without strict validation.\n     * <p>\n     * Note that the host-only formats will leave the port field undefined.  You\n     * can use {@link #withDefaultPort(int)} to patch in a default value.\n     *\n     * @param hostPortString the input string to parse.\n     * @return if parsing was successful, a populated HostAddress object.","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java#L133-L169","documentation":"HostAddress.fromParts builds a HostAddress from an explicit host string and port. The port must satisfy isValidPort (0..65535; typically 1..65535 usable); an out-of-range int is rejected before any parsing so callers get a clear message instead of a malformed address.","triggerScenarios":"Calling HostAddress.fromParts(host, port) where port is negative, greater than 65535, or otherwise fails isValidPort — often a port parsed from config or a URI default of 0/-1.","commonSituations":"Port read from an unset config property defaulting to 0; integer overflow or truncated string parse; concatenating host:port strings and re-splitting incorrectly before calling fromParts.","solutions":["Validate the port is in 1..65535 before calling fromParts","Check the config/default value supplying the port (e.g. http-server.port) is actually set","Parse host and port with HostAddress.fromUri(String) instead of splitting manually"],"exampleFix":"// before\nint port = config.getPort(); // 0 when unset\nHostAddress addr = HostAddress.fromParts(host, port);\n// after\nint port = config.getPort();\nif (port < 1 || port > 65535) { throw new ConfigException(\"invalid port: \" + port); }\nHostAddress addr = HostAddress.fromParts(host, port);","handlingStrategy":"validation","validationCode":"if (port < 1 || port > 65535) {\n    throw new IllegalArgumentException(\"Port must be in 1..65535, got: \" + port);\n}","typeGuard":null,"tryCatchPattern":"try {\n    addr = HostAddress.fromParts(host, port);\n} catch (IllegalArgumentException e) {\n    throw new ConfigException(\"Invalid port for host \" + host + \": \" + port, e);\n}","preventionTips":["Validate ports at config load time","Avoid sentinel defaults like 0 or -1 for ports","Prefer fromUri/fromString for URI-derived addresses"],"tags":["spi","network","host-address","port-validation"],"backgroundTag":"invalid-port","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}