{"record":{"id":"054ed25b8e416061","repo":"prestodb/presto","slug":"host-contains-a-port-declaration","errorCode":null,"errorMessage":"host contains a port declaration: ","messagePattern":"host contains a port declaration: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java","lineNumber":155,"sourceCode":"    /**\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.\n     * @throws IllegalArgumentException if nothing meaningful could be parsed.\n     */\n    @JsonCreator\n    public static HostAddress fromString(String hostPortString)","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java#L137-L173","documentation":"fromParts expects the host string to be a bare host (or IPv6 literal without port). If fromString(host) detects an embedded port in the host argument, fromParts rejects it because the port would conflict with the explicit port parameter. The port must be supplied via the separate port argument.","triggerScenarios":"Calling HostAddress.fromParts(\"example.com:8080\", 9090) or fromParts(\"[::1]:8080\", 9090) — i.e. passing a host string that still contains \":port\" or a bracketed host-with-port.","commonSituations":"Splitting \"host:port\" config strings on the first colon only, leaving the port in the host; passing a full URI authority string as the host argument; IPv6 addresses where naive colon splitting fails.","solutions":["Strip the port from the host string before calling fromParts","Use HostAddress.fromString(\"host:port\") to parse a combined string instead of fromParts","Use HostAddress.fromUri(URI) when the source is a URI","For IPv6 literals, pass the bracket-stripped address as host and the port separately"],"exampleFix":"// before\nHostAddress.fromParts(\"example.com:8080\", 9090);\n// after\nHostAddress.fromParts(\"example.com\", 9090);\n// or\nHostAddress.fromString(\"example.com:8080\");","handlingStrategy":"validation","validationCode":"if (host != null && (host.contains(\":\") && !(host.startsWith(\"[\") && host.endsWith(\"]\")))) {\n    throw new IllegalArgumentException(\"Host must not contain a port: \" + host);\n}","typeGuard":null,"tryCatchPattern":"try {\n    addr = HostAddress.fromParts(host, port);\n} catch (IllegalArgumentException e) {\n    // host string had embedded port; fall back to combined parse\n    addr = HostAddress.fromString(host);\n}","preventionTips":["Strip any :port from host strings before fromParts","Use fromString or fromUri for combined host:port input","Split config values on the last colon (rsplit) to keep IPv6 intact"],"tags":["spi","network","host-address","port-validation"],"backgroundTag":"host-string-contains-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"}