{"record":{"id":"36a68967b6dbd918","repo":"theonedev/onedev","slug":"cannot-match-on-empty-string","errorCode":null,"errorMessage":"Cannot match on empty string.","messagePattern":"Cannot match on empty string\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/eclipse/jgit/revwalk/filter/AuthorRevFilter.java","lineNumber":41,"sourceCode":"public class AuthorRevFilter {\n\t/**\n\t * Create a new author filter.\n\t * <p>\n\t * An optimized substring search may be automatically selected if the\n\t * pattern does not contain any regular expression meta-characters.\n\t * <p>\n\t * The search is performed using a case-insensitive comparison. The\n\t * character encoding of the commit message itself is not respected. The\n\t * filter matches on raw UTF-8 byte sequences.\n\t *\n\t * @param pattern\n\t *            regular expression pattern to match.\n\t * @return a new filter that matches the given expression against the author\n\t *         name and address of a commit.\n\t */\n\tpublic static RevFilter create(String pattern) {\n\t\tif (pattern.length() == 0)\n\t\t\tthrow new IllegalArgumentException(JGitText.get().cannotMatchOnEmptyString);\n\t\tif (SubStringRevFilter.safe(pattern))\n\t\t\treturn new SubStringSearch(pattern);\n\t\treturn new PatternSearch(pattern);\n\t}\n\n\tprivate AuthorRevFilter() {\n\t\t// Don't permit us to be created.\n\t}\n\n\tstatic RawCharSequence textFor(RevCommit cmit) {\n\t\tfinal byte[] raw = cmit.getRawBuffer();\n\t\tfinal int b = RawParseUtils.author(raw, 0);\n\t\tif (b < 0)\n\t\t\treturn RawCharSequence.EMPTY;\n\t\tfinal int e = RawParseUtils.nextLF(raw, b, '>');\n\t\treturn new RawCharSequence(raw, b, e);\n\t}\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/eclipse/jgit/revwalk/filter/AuthorRevFilter.java#L23-L59","documentation":"AuthorRevFilter.create(String) throws IllegalArgumentException when the pattern is the empty string. An empty regex or substring would match every commit author, which is almost certainly a caller bug, so JGit rejects it eagerly.","triggerScenarios":"Calling AuthorRevFilter.create(\"\") — typically when a user-supplied search string was empty or the variable was never populated.","commonSituations":"CLI/git-swing search boxes passed through without trimming or emptiness checks; config values defaulting to empty string instead of null meaning 'no filter'.","solutions":["Validate the pattern is non-empty before calling create and skip filter creation (use RevFilter.NONE or no filter) when empty","Trim user input first; treat whitespace-only as empty and reject or ignore","In UI/CLI layers, require the search field to be non-blank before constructing the filter"],"exampleFix":"// before\nRevFilter f = AuthorRevFilter.create(userInput);\n// after\nif (userInput == null || userInput.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"author pattern must not be empty\");\n}\nRevFilter f = AuthorRevFilter.create(userInput);","handlingStrategy":"validation","validationCode":"String p = userInput == null ? \"\" : userInput.trim();\nif (p.isEmpty()) { throw new IllegalArgumentException(\"author pattern must not be empty\"); }","typeGuard":"boolean validPattern(String s) { return s != null && !s.trim().isEmpty(); }","tryCatchPattern":"try {\n    RevFilter f = AuthorRevFilter.create(pattern);\n} catch (IllegalArgumentException e) {\n    // fall back: no author filter or report empty search term to user\n}","preventionTips":["Trim and validate search input before constructing filters","Treat empty input as 'no filter' rather than passing it through","Add non-empty assertions where patterns come from config"],"tags":["jgit","revfilter","illegal-argument","empty-string"],"backgroundTag":"empty-required-field","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}