{"record":{"id":"223c48f4abf012d7","repo":"theonedev/onedev","slug":"cannot-match-on-empty-string-223c48","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/MessageRevFilter.java","lineNumber":41,"sourceCode":"public class MessageRevFilter {\n\t/**\n\t * Create a message 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\n\t *         message body of the 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 MessageRevFilter() {\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.commitMessage(raw, 0);\n\t\tif (b < 0)\n\t\t\treturn RawCharSequence.EMPTY;\n\t\treturn new RawCharSequence(raw, b, raw.length);\n\t}\n\n\tprivate static class PatternSearch extends PatternMatchRevFilter {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/eclipse/jgit/revwalk/filter/MessageRevFilter.java#L23-L59","documentation":"MessageRevFilter.create(String) throws IllegalArgumentException when the pattern is an empty string. Matching against the commit message with an empty expression would match every commit, so JGit treats it as an invalid input.","triggerScenarios":"Calling MessageRevFilter.create(\"\") — e.g. an empty search box value or defaulted config string passed to the factory.","commonSituations":"Commit message search features that don't validate input; log-parsing scripts where the pattern variable came out empty after tokenizing arguments.","solutions":["Validate the pattern is non-empty (after trim) before calling create; skip the filter when empty","Trim and check user input at the CLI/UI boundary","Use null or Optional<String> to represent 'no message filter' instead of \"\""],"exampleFix":"// before\nRevFilter f = MessageRevFilter.create(pattern);\n// after\nif (pattern == null || pattern.trim().isEmpty()) {\n    return RevFilter.ALL; // or don't add the filter\n}\nRevFilter f = MessageRevFilter.create(pattern);","handlingStrategy":"validation","validationCode":"String p = userInput == null ? \"\" : userInput.trim();\nif (p.isEmpty()) { throw new IllegalArgumentException(\"message pattern must not be empty\"); }","typeGuard":"boolean validPattern(String s) { return s != null && !s.trim().isEmpty(); }","tryCatchPattern":"try {\n    RevFilter f = MessageRevFilter.create(pattern);\n} catch (IllegalArgumentException e) {\n    // skip the message filter or report empty search input\n}","preventionTips":["Validate search terms before building commit filters","Represent missing criteria as null/Optional, not \"\"","Cover empty-input paths in UI/CLI validation"],"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"}