{"record":{"id":"aa17dd068a6d66b6","repo":"theonedev/onedev","slug":"cannot-match-on-empty-string-aa17dd","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/PatternMatchRevFilter.java","lineNumber":74,"sourceCode":"\t *\n\t * @param pattern\n\t *            text of the pattern. Callers may want to surround their\n\t *            pattern with \".*\" on either end to allow matching in the\n\t *            middle of the string.\n\t * @param innerString\n\t *            should .* be wrapped around the pattern of ^ and $ are\n\t *            missing? Most users will want this set.\n\t * @param rawEncoding\n\t *            should {@link #forceToRaw(String)} be applied to the pattern\n\t *            before compiling it?\n\t * @param flags\n\t *            flags from {@link java.util.regex.Pattern} to control how\n\t *            matching performs.\n\t */\n\tprotected PatternMatchRevFilter(String pattern, final boolean innerString,\n\t\t\tfinal boolean rawEncoding, final int flags) {\n\t\tif (pattern.length() == 0)\n\t\t\tthrow new IllegalArgumentException(JGitText.get().cannotMatchOnEmptyString);\n\t\tpatternText = pattern;\n\n\t\tif (innerString) {\n\t\t\tif (!pattern.startsWith(\"^\") && !pattern.startsWith(\".*\")) //$NON-NLS-1$ //$NON-NLS-2$\n\t\t\t\tpattern = \".*\" + pattern; //$NON-NLS-1$\n\t\t\tif (!pattern.endsWith(\"$\") && !pattern.endsWith(\".*\")) //$NON-NLS-1$ //$NON-NLS-2$\n\t\t\t\tpattern = pattern + \".*\"; //$NON-NLS-1$\n\t\t}\n\t\tfinal String p = rawEncoding ? forceToRaw(pattern) : pattern;\n\t\tcompiledPattern = Pattern.compile(p, flags).matcher(\"\"); //$NON-NLS-1$\n\t}\n\n\t/**\n\t * Get the pattern this filter uses.\n\t *\n\t * @return the pattern this filter is applying to candidate strings.\n\t */\n\tpublic String pattern() {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java#L56-L92","documentation":"PatternMatchRevFilter is the abstract base for rev-walk commit-message filters (e.g. SubstringRevFilter, PatternMatchRevFilter subclasses) in JGit. Its constructor rejects an empty pattern string because matching every commit against an empty pattern is not meaningful. Passing \"\" throws IllegalArgumentException.","triggerScenarios":"Constructing a subclass of PatternMatchRevFilter with pattern=\"\" or pattern that is empty after trimming, e.g. from an empty --grep= option or a blank search box in a UI.","commonSituations":"Wiring a git-log search UI where the user submits an empty search term; parsing CLI flags like --author= or --grep= with empty values and forwarding them to JGit.","solutions":["Validate the pattern is non-empty before constructing the filter","Return early or disable the search when the user supplies an empty term","Trim and check the input string before passing it to the filter constructor"],"exampleFix":"// before\nRevFilter f = new PatternMatchRevFilter(userInput, true, true, Pattern.CASE_INSENSITIVE);\n// after\nif (userInput == null || userInput.isEmpty()) return RevFilter.NONE;\nRevFilter f = new PatternMatchRevFilter(userInput, true, true, Pattern.CASE_INSENSITIVE);","handlingStrategy":"validation","validationCode":"if (pattern == null || pattern.isEmpty()) { /* skip search / use RevFilter.NONE */ }","typeGuard":"boolean isUsablePattern(String p) { return p != null && !p.trim().isEmpty(); }","tryCatchPattern":"try { return new SubstringRevFilter(pattern); } catch (IllegalArgumentException e) { log.warn(\"Empty pattern\"); return RevFilter.NONE; }","preventionTips":["Trim and validate search input from UIs and CLI before constructing filters","Treat empty search terms as 'no filter' rather than passing them through"],"tags":["jgit","regex","pattern","illegal-argument"],"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-14T05:17:10.506Z"}