{"record":{"id":"a90eef8cc4710f63","repo":"apache/druid","slug":"failed-to-parse-address","errorCode":null,"errorMessage":"failed to parse address","messagePattern":"failed to parse address","errorType":"validation","errorClass":"DruidException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/expression/IPv4AddressMatchExprMacro.java","lineNumber":129,"sourceCode":"        private boolean isLongMatch(long longValue)\n        {\n          IPv4Address address = IPv4AddressExprUtils.parse(longValue);\n          return address != null && block.contains(address);\n        }\n\n        @Nullable\n        @Override\n        public ExpressionType getOutputType(InputBindingInspector inspector)\n        {\n          return ExpressionType.LONG;\n        }\n      }\n\n      return new IPv4AddressMatchExpr(args);\n    }\n\n    catch (AddressStringException e) {\n      throw processingFailed(e, \"failed to parse address\");\n    }\n  }\n\n  private IPAddressString getSubnetInfo(List<Expr> args)\n  {\n    String subnetArgName = \"subnet\";\n    Expr arg = args.get(ARG_SUBNET);\n    validationHelperCheckArgIsLiteral(arg, subnetArgName);\n    String subnet = (String) arg.getLiteralValue();\n    if (!IPv4AddressExprUtils.isValidIPv4Subnet(subnet)) {\n      throw validationFailed(subnetArgName + \" arg has an invalid format: \" + subnet);\n    }\n    return new IPAddressString(subnet);\n  }\n}\n","sourceCodeStart":111,"sourceCodeEnd":145,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/expression/IPv4AddressMatchExprMacro.java#L111-L145","documentation":"The IPV4_MATCH expression macro uses the IPAddressString library to parse its address argument during compilation. If the underlying IPAddressString raises an AddressStringException while interpreting the address/subnet, Druid wraps it as an expression processing failure with message 'failed to parse address'.","triggerScenarios":"Invoking IPV4_MATCH with an address expression or literal that the IPAddress library cannot parse at apply-time, e.g. malformed IPv4 input that trips AddressStringException rather than merely returning false.","commonSituations":"Feeding raw, unvalidated user-supplied IP strings into IPV4_MATCH; regional or unusual address formats (e.g. values with zone IDs or octal segments) that the parsing library rejects as invalid rather than unparseable.","solutions":["Validate the input with IPv4AddressExprUtils.isValidIPv4(addr) (or a regex like ^(\\d{1,3}\\.){3}\\d{1,3}$) before passing it to IPV4_MATCH.","Normalize the address string (trim whitespace, strip port/zone suffixes) upstream in your ingestion or query-building code.","Ensure the first argument resolves to a plain IPv4 string at evaluation time; check the column's values for junk rows."],"exampleFix":"// before\nexpr = \"IPV4_MATCH(ip, '10.0.0.0/8')\"; // ip may contain junk like '10.0.0.1:80'\n// after\nexpr = \"IPV4_MATCH(REGEXP_EXTRACT(ip, '^((\\\\d{1,3}\\\\.){3}\\\\d{1,3})', 1), '10.0.0.0/8')\"","handlingStrategy":"validation","validationCode":"// Java\nif (!IPv4AddressExprUtils.isValidIPv4(candidate)) { throw new IllegalArgumentException(\"not a valid IPv4 address: \" + candidate); }","typeGuard":"static boolean looksLikeIPv4(String s) {\n  return s != null && s.matches(\"^(\\\\d{1,3}\\\\.){3}\\\\d{1,3}$\");\n}","tryCatchPattern":"try {\n  return evalExpression(expr);\n} catch (ExpressionProcessingException e) {\n  if (e.getMessage().contains(\"failed to parse address\")) {\n    log.warn(\"Skipping unparseable IP value\");\n    return null;\n  }\n  throw e;\n}","preventionTips":["Sanitize IP columns during ingestion (strip ports, zone IDs, whitespace).","Pre-validate literals with the same utils Druid uses (isValidIPv4).","Prefer returning 'no match' semantics via pre-filtering rather than feeding junk to IPV4_MATCH."],"tags":["druid","expression","ipv4","parse-error"],"backgroundTag":"invalid-argument-format","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}