{"record":{"id":"de0e6fad9d8c165c","repo":"openzipkin/zipkin","slug":"s-is-an-invalid-ipv6-literal","errorCode":null,"errorMessage":"%s is an invalid IPv6 literal","messagePattern":"(.+?) is an invalid IPv6 literal","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"zipkin-storage/cassandra/src/main/java/zipkin2/storage/cassandra/internal/HostAndPort.java","lineNumber":70,"sourceCode":"  public static HostAndPort fromString(String hostPort, int defaultPort) {\n    if (hostPort == null) throw new NullPointerException(\"hostPort == null\");\n\n    String host = hostPort;\n    int endHostIndex = hostPort.length();\n    if (hostPort.startsWith(\"[\")) { // Bracketed IPv6\n      endHostIndex = hostPort.lastIndexOf(']') + 1;\n      host = hostPort.substring(1, endHostIndex == 0 ? 1 : endHostIndex - 1);\n      if (!Endpoint.newBuilder().parseIp(host)) { // reuse our IPv6 validator\n        throw new IllegalArgumentException(hostPort + \" contains an invalid IPv6 literal\");\n      }\n    } else {\n      int colonIndex = hostPort.indexOf(':'), nextColonIndex = hostPort.lastIndexOf(':');\n      if (colonIndex >= 0) {\n        if (colonIndex == nextColonIndex) { // only 1 colon\n          host = hostPort.substring(0, colonIndex);\n          endHostIndex = colonIndex;\n        } else if (!Endpoint.newBuilder().parseIp(hostPort)) { // reuse our IPv6 validator\n          throw new IllegalArgumentException(hostPort + \" is an invalid IPv6 literal\");\n        }\n      }\n    }\n    if (host.isEmpty()) throw new IllegalArgumentException(hostPort + \" has an empty host\");\n    if (endHostIndex + 1 < hostPort.length() && hostPort.charAt(endHostIndex) == ':') {\n      return new HostAndPort(host, validatePort(hostPort.substring(endHostIndex + 1), hostPort));\n    }\n    return new HostAndPort(host, defaultPort);\n  }\n\n  static int validatePort(String portString, String hostPort) {\n    for (int i = 0, length = portString.length(); i < length; i++) {\n      char c = portString.charAt(i);\n      if (c >= '0' && c <= '9') continue; // isDigit\n      throw new IllegalArgumentException(hostPort + \" has an invalid port\");\n    }\n    int result = Integer.parseInt(portString);\n    if (result == 0 || result > 0xffff) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/openzipkin/zipkin/blob/878ce2a1fad54ca941d17fdcf2e1d924b148eb1f/zipkin-storage/cassandra/src/main/java/zipkin2/storage/cassandra/internal/HostAndPort.java#L52-L88","documentation":"Thrown by HostAndPort.fromString when the input contains multiple colons and is not bracketed, and the whole string fails IPv6 validation (it reuses Endpoint's IPv6 validator). An unbracketed multi-colon string can only be legal bare IPv6; anything else (e.g. 'host:1:2') is invalid.","triggerScenarios":"Passing '2001:db8::1:9042' where the embedded ':9042' makes the full string an invalid IPv6 address; passing 'a:b:c' style strings.","commonSituations":"Forgetting to bracket an IPv6 address that carries a port; config values joined with extra colons.","solutions":["Bracket IPv6 with a port: '[2001:db8::1]:9042'.","For bare IPv6 without port, pass '2001:db8::1' and let defaultPort apply.","Lint contact-point strings at config load for the bracket rule."],"exampleFix":"# before\nCASSANDRA_CONTACT_POINTS=2001:db8::1:9042\n\n# after\nCASSANDRA_CONTACT_POINTS=[2001:db8::1]:9042","handlingStrategy":"validation","validationCode":"static boolean isBareIpv6(String s) { return s != null && s.indexOf(':') != s.lastIndexOf(':') && Endpoint.newBuilder().parseIp(s); }\n// When a port is needed with IPv6, require brackets\nif (hostPort.indexOf(':') != hostPort.lastIndexOf(':') && !hostPort.startsWith(\"[\")) throw new IllegalArgumentException(\"Bracket IPv6 with port: [addr]:port\");","typeGuard":"static boolean isIpv6WithOptionalPort(String s) { return s != null && (isBareIpv6(s) || isValidBracketedIpv6(s)); }","tryCatchPattern":"catch (IllegalArgumentException e) { if (e.getMessage().endsWith(\"is an invalid IPv6 literal\")) suggestBracketedForm(); else throw e; }","preventionTips":["Standardize the '[IPv6]:port' form in all configs.","Add a config lint rule: >1 colon and no bracket = reject."],"tags":["cassandra","zipkin","ipv6","contact-points","validation"],"backgroundTag":null,"analyzedSha":"878ce2a1fad54ca941d17fdcf2e1d924b148eb1f","analyzedAt":"2026-08-14T15:17:09.895Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}