{"record":{"id":"fcf8de2cb0d891cd","repo":"prestodb/presto","slug":"invalid-bracketed-host-port","errorCode":null,"errorMessage":"Invalid bracketed host/port: ","messagePattern":"Invalid bracketed host/port: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java","lineNumber":183,"sourceCode":"     * 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)\n    {\n        requireNonNull(hostPortString, \"hostPortString is null\");\n        String host;\n        String portString = null;\n\n        if (hostPortString.startsWith(\"[\")) {\n            // Parse a bracketed host, typically an IPv6 literal.\n            Matcher matcher = BRACKET_PATTERN.matcher(hostPortString);\n            if (!matcher.matches()) {\n                throw new IllegalArgumentException(\"Invalid bracketed host/port: \" + hostPortString);\n            }\n            host = matcher.group(1);\n            portString = matcher.group(2);  // could be null\n        }\n        else {\n            int colonPos = hostPortString.indexOf(':');\n            if (colonPos >= 0 && hostPortString.indexOf(':', colonPos + 1) == -1) {\n                // Exactly 1 colon.  Split into host:port.\n                host = hostPortString.substring(0, colonPos);\n                portString = hostPortString.substring(colonPos + 1);\n            }\n            else {\n                // 0 or 2+ colons.  Bare hostname or IPv6 literal.\n                host = hostPortString;\n            }\n        }\n\n        int port = NO_PORT;","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-spi/src/main/java/com/facebook/presto/spi/HostAddress.java#L165-L201","documentation":"HostAddress.fromString parses \"host[:port]\" strings. Strings starting with '[' are treated as bracketed IPv6 literals and must match the pattern ^\\[(.*:.*)\\](?::(\\d*))?$ — brackets enclosing at least one colon, with an optional :port suffix. Anything else bracketed (missing closing bracket, no colon inside, junk after the port) is rejected as unparseable.","triggerScenarios":"Calling HostAddress.fromString with a malformed bracketed literal such as \"[::1\", \"[::1]x\", \"[localhost]\", or \"[::1]:port\" where port is non-numeric with extra characters.","commonSituations":"Manually truncating IPv6 strings (cutting off the closing bracket); users typing IPv6 without brackets; log/config values where the address was concatenated with a path or trailing text.","solutions":["Ensure IPv6 literals are fully bracketed and contain colons: \"[2001:db8::1]\" or \"[::1]:8080\"","Strip any trailing garbage (paths, whitespace) before parsing","For non-IPv6 hosts, remove the brackets entirely","Prefer fromUri(URI) when input comes from a URI"],"exampleFix":"// before\nHostAddress.fromString(\"[2001:db8::1\");\n// after\nHostAddress.fromString(\"[2001:db8::1]:8080\");\n// or\nHostAddress.fromString(\"2001:db8::1\").withDefaultPort(8080);","handlingStrategy":"validation","validationCode":"private static final Pattern BRACKETED = Pattern.compile(\"^\\\\[(.*:.*)\\\\](?::(\\\\d*))?$\");\nif (hostPort.startsWith(\"[\") && !BRACKETED.matcher(hostPort).matches()) {\n    throw new IllegalArgumentException(\"Malformed bracketed IPv6 literal: \" + hostPort);\n}","typeGuard":null,"tryCatchPattern":"try {\n    addr = HostAddress.fromString(hostPort);\n} catch (IllegalArgumentException e) {\n    log.error(\"Cannot parse address '%s'\", hostPort, e);\n    addr = null;\n}","preventionTips":["Always fully bracket IPv6 literals: [::1], optionally [::1]:8080","Trim and sanitize address strings from configs/logs before parsing","Prefer fromUri(URI) for URI-sourced values"],"tags":["spi","network","host-address","ipv6","parsing"],"backgroundTag":"invalid-ipv6-literal","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"}