{"record":{"id":"09baaa8c8ff42f80","repo":"apache/druid","slug":"could-not-parse-fileregex-s","errorCode":null,"errorMessage":"Could not parse `fileRegex` [%s]","messagePattern":"Could not parse `fileRegex` \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-core/lookups-cached-global/src/main/java/org/apache/druid/query/lookup/namespace/UriExtractionNamespace.java","lineNumber":133,"sourceCode":"      this.pollPeriod = Period.ZERO;\n    } else {\n      this.pollPeriod = pollPeriod;\n    }\n    this.fileRegex = fileRegex == null ? versionRegex : fileRegex;\n    if (fileRegex != null && versionRegex != null) {\n      throw new IAE(\"Cannot specify both versionRegex and fileRegex. versionRegex is deprecated\");\n    }\n\n    if (uri != null && this.fileRegex != null) {\n      throw new IAE(\"Cannot define both uri and fileRegex\");\n    }\n\n    if (this.fileRegex != null) {\n      try {\n        Pattern.compile(this.fileRegex);\n      }\n      catch (PatternSyntaxException ex) {\n        throw new IAE(ex, \"Could not parse `fileRegex` [%s]\", this.fileRegex);\n      }\n    }\n    this.maxHeapPercentage = maxHeapPercentage == null ? DEFAULT_MAX_HEAP_PERCENTAGE : maxHeapPercentage;\n  }\n\n  public String getFileRegex()\n  {\n    return fileRegex;\n  }\n\n  public FlatDataParser getNamespaceParseSpec()\n  {\n    return this.namespaceParseSpec;\n  }\n\n  public URI getUri()\n  {\n    return uri;","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/lookups-cached-global/src/main/java/org/apache/druid/query/lookup/namespace/UriExtractionNamespace.java#L115-L151","documentation":"After the mutually-exclusive checks, UriExtractionNamespace's constructor validates fileRegex by compiling it with Pattern.compile. A PatternSyntaxException is rethrown as this IAE (with the bad pattern and the cause attached), so malformed regexes fail fast at config load instead of at poll time.","triggerScenarios":"Providing a syntactically invalid fileRegex (e.g. \"[a-\", \"*foo\", unbalanced parentheses, bad escape like \"\\\\\\\\\" errors) in the UriExtractionNamespace config.","commonSituations":"Regexes written for grep/sed syntax rather than Java regex; unescaped dots/brackets in filename patterns; string-escaping mistakes in JSON where backslashes were consumed by the JSON parser, leaving an invalid Java pattern.","solutions":["Fix the fileRegex to be a valid Java regular expression; test it with Pattern.compile or a Java-regex validator.","Double JSON backslashes in escape sequences (e.g. \".*\\\\\\\\.csv\" in JSON for \".*\\\\.csv\" in Java).","Check the wrapped PatternSyntaxException message for the exact character index of the syntax error.","Simplify the pattern or use a broader prefix match if complex filtering is unnecessary."],"exampleFix":"// before (invalid Java regex)\n\"fileRegex\": \"[a-z\"\n// after\n\"fileRegex\": \"[a-z]+\\\\.csv\"","handlingStrategy":"validation","validationCode":"// java\nString regex = cfg.get(\"fileRegex\").asText();\ntry { java.util.regex.Pattern.compile(regex); }\ncatch (java.util.regex.PatternSyntaxException e) {\n  throw new IllegalArgumentException(\"bad fileRegex: \" + e.getMessage());\n}","typeGuard":null,"tryCatchPattern":"// java\ntry { mapper.readValue(json, UriExtractionNamespace.class); }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"Could not parse `fileRegex`\")) { /* fix pattern */ }\n}","preventionTips":["Compile the pattern with Pattern.compile in a unit test before shipping configs.","Remember JSON string escaping: double backslashes for regex escapes.","Use Java-flavored regex syntax, not grep/PCRE extensions."],"tags":["lookup","regex","configuration","validation"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}