{"record":{"id":"dc1ec957d0060633","repo":"prestodb/presto","slug":"port-number-out-of-range","errorCode":null,"errorMessage":"Port number out of range: ","messagePattern":"Port number out of range: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java","lineNumber":215,"sourceCode":"                host = hostPortString;\n            }\n        }\n\n        int port = NO_PORT;\n        if (portString != null && portString.length() != 0) {\n            // Try to parse the whole port string as a number.\n            // JDK7 accepts leading plus signs. We don't want to.\n            if (portString.startsWith(\"+\")) {\n                throw new IllegalArgumentException(\"Unparseable port number: \" + hostPortString);\n            }\n            try {\n                port = Integer.parseInt(portString);\n            }\n            catch (NumberFormatException e) {\n                throw new IllegalArgumentException(\"Unparseable port number: \" + hostPortString);\n            }\n            if (!isValidPort(port)) {\n                throw new IllegalArgumentException(\"Port number out of range: \" + hostPortString);\n            }\n        }\n\n        return new HostAddress(host, port);\n    }\n\n    public static HostAddress fromUri(URI httpUri)\n    {\n        String host = httpUri.getHost();\n        int port = httpUri.getPort();\n        if (port < 0) {\n            return fromString(host);\n        }\n        else {\n            return fromParts(host, port);\n        }\n    }\n","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java#L197-L233","documentation":"After fromString successfully parses the port as an integer it must still pass isValidPort (0..65535). Integers outside that range — e.g. 70000 or 999999999 — parse fine but are not legal ports, so parsing fails with \"Port number out of range\" quoting the full hostPortString.","triggerScenarios":"HostAddress.fromString(\"host:70000\") or \"host:65536\" — syntactically numeric, int-parseable, but outside the valid 0..65535 port range.","commonSituations":"Confusing port with other numeric fields (PID, inode); decimal/hex mixups (0x10000 typed as 10000 in wrong base); randomly generated invalid ports in tests; shifted digits from typos.","solutions":["Check the port is within 0..65535 (operationally 1..65535) before parsing","Correct the port value in the config/URI that supplies it","Reuse isValidPort-style validation at the config boundary so the failure happens earlier","Generate test ports with RandomPort utilities instead of arbitrary numbers"],"exampleFix":"// before\nHostAddress.fromString(\"localhost:70000\");\n// after\nHostAddress.fromString(\"localhost:65535\");\n// or guard first\nif (port < 1 || port > 65535) throw new IllegalArgumentException(\"bad port\");","handlingStrategy":"validation","validationCode":"int idx = hostPort.lastIndexOf(':');\nint p = Integer.parseInt(hostPort.substring(idx + 1).trim());\nif (p < 0 || p > 65535) {\n    throw new IllegalArgumentException(\"Port number out of range: \" + p);\n}","typeGuard":null,"tryCatchPattern":"try {\n    addr = HostAddress.fromString(hostPort);\n} catch (IllegalArgumentException e) {\n    throw new IllegalArgumentException(\"Invalid port in address: \" + hostPort, e);\n}","preventionTips":["Range-check ports 0..65535 at the config boundary","Don't conflate ports with other numeric identifiers","Use well-known scheme defaults (80/443) instead of ad-hoc large numbers"],"tags":["spi","network","host-address","port-validation","range-check"],"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"}