theonedev/onedev · error · IllegalArgumentException
Cannot match on empty string.
Error message
Cannot match on empty string.
What it means
CommitterRevFilter.create(String) throws IllegalArgumentException when given an empty pattern string. Committer matching with an empty expression would match every commit, so JGit rejects it as a programming error.
Source
Thrown at server-core/src/main/java/org/eclipse/jgit/revwalk/filter/CommitterRevFilter.java:41
public class CommitterRevFilter {
/**
* Create a new committer filter.
* <p>
* An optimized substring search may be automatically selected if the
* pattern does not contain any regular expression meta-characters.
* <p>
* The search is performed using a case-insensitive comparison. The
* character encoding of the commit message itself is not respected. The
* filter matches on raw UTF-8 byte sequences.
*
* @param pattern
* regular expression pattern to match.
* @return a new filter that matches the given expression against the author
* name and address of a commit.
*/
public static RevFilter create(String pattern) {
if (pattern.length() == 0)
throw new IllegalArgumentException(JGitText.get().cannotMatchOnEmptyString);
if (SubStringRevFilter.safe(pattern))
return new SubStringSearch(pattern);
return new PatternSearch(pattern);
}
private CommitterRevFilter() {
// Don't permit us to be created.
}
static RawCharSequence textFor(RevCommit cmit) {
final byte[] raw = cmit.getRawBuffer();
final int b = RawParseUtils.committer(raw, 0);
if (b < 0)
return RawCharSequence.EMPTY;
final int e = RawParseUtils.nextLF(raw, b, '>');
return new RawCharSequence(raw, b, e);
}
View on GitHub (pinned to d44925c47c)
Solutions
- Check pattern.length() > 0 before calling create; omit the filter entirely when empty
- Trim/validate user input at the entry point
- Represent 'no committer filter' with null or Optional instead of an empty string
Example fix
// before
RevFilter f = CommitterRevFilter.create(pattern);
// after
if (pattern.isEmpty()) {
return RevFilter.ALL; // or skip adding the filter
}
RevFilter f = CommitterRevFilter.create(pattern); Defensive patterns
Strategy: validation
Validate before calling
String p = userInput == null ? "" : userInput.trim();
if (p.isEmpty()) { throw new IllegalArgumentException("committer pattern must not be empty"); } Type guard
boolean validPattern(String s) { return s != null && !s.trim().isEmpty(); } Try / catch
try {
RevFilter f = CommitterRevFilter.create(pattern);
} catch (IllegalArgumentException e) {
// use RevFilter.ALL or surface a validation message
} Prevention
- Never pass empty strings as match patterns; use null/Optional for 'absent'
- Validate at the input boundary (CLI args, form fields)
- Include committer-pattern emptiness in input validation tests
When it happens
Trigger: Calling CommitterRevFilter.create("") — e.g. an empty search term passed straight from user input or an unset config default.
Common situations: Search forms submitted blank; scripts building commit queries with optional committer criteria that defaulted to "" rather than being omitted.
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
- Cannot match on empty string.
- Cannot match on empty string.
- At least two filters needed.
- Max count must be non-negative.
- At least two filters needed.
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/e9390b6ac3c026a9.
Report an issue: GitHub.