theonedev/onedev · error · IllegalArgumentException
Cannot match on empty string.
Error message
Cannot match on empty string.
What it means
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.
Source
Thrown at server-core/src/main/java/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java:74
*
* @param pattern
* text of the pattern. Callers may want to surround their
* pattern with ".*" on either end to allow matching in the
* middle of the string.
* @param innerString
* should .* be wrapped around the pattern of ^ and $ are
* missing? Most users will want this set.
* @param rawEncoding
* should {@link #forceToRaw(String)} be applied to the pattern
* before compiling it?
* @param flags
* flags from {@link java.util.regex.Pattern} to control how
* matching performs.
*/
protected PatternMatchRevFilter(String pattern, final boolean innerString,
final boolean rawEncoding, final int flags) {
if (pattern.length() == 0)
throw new IllegalArgumentException(JGitText.get().cannotMatchOnEmptyString);
patternText = pattern;
if (innerString) {
if (!pattern.startsWith("^") && !pattern.startsWith(".*")) //$NON-NLS-1$ //$NON-NLS-2$
pattern = ".*" + pattern; //$NON-NLS-1$
if (!pattern.endsWith("$") && !pattern.endsWith(".*")) //$NON-NLS-1$ //$NON-NLS-2$
pattern = pattern + ".*"; //$NON-NLS-1$
}
final String p = rawEncoding ? forceToRaw(pattern) : pattern;
compiledPattern = Pattern.compile(p, flags).matcher(""); //$NON-NLS-1$
}
/**
* Get the pattern this filter uses.
*
* @return the pattern this filter is applying to candidate strings.
*/
public String pattern() {View on GitHub (pinned to d44925c47c)
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
Example fix
// before RevFilter f = new PatternMatchRevFilter(userInput, true, true, Pattern.CASE_INSENSITIVE); // after if (userInput == null || userInput.isEmpty()) return RevFilter.NONE; RevFilter f = new PatternMatchRevFilter(userInput, true, true, Pattern.CASE_INSENSITIVE);
Defensive patterns
Strategy: validation
Validate before calling
if (pattern == null || pattern.isEmpty()) { /* skip search / use RevFilter.NONE */ } Type guard
boolean isUsablePattern(String p) { return p != null && !p.trim().isEmpty(); } Try / catch
try { return new SubstringRevFilter(pattern); } catch (IllegalArgumentException e) { log.warn("Empty pattern"); return RevFilter.NONE; } Prevention
- Trim and validate search input from UIs and CLI before constructing filters
- Treat empty search terms as 'no filter' rather than passing them through
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- At least two filters needed.
- Cannot match on empty string.
- Cannot match on empty string.
- Max count must be non-negative.
- Cannot match on empty string.
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/aa17dd068a6d66b6.
Report an issue: GitHub.