theonedev/onedev · error · IllegalArgumentException
Cannot match on empty string.
Error message
Cannot match on empty string.
What it means
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.
Source
Thrown at server-core/src/main/java/org/eclipse/jgit/revwalk/filter/MessageRevFilter.java:41
public class MessageRevFilter {
/**
* Create a message 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
* message body of the 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 MessageRevFilter() {
// Don't permit us to be created.
}
static RawCharSequence textFor(RevCommit cmit) {
final byte[] raw = cmit.getRawBuffer();
final int b = RawParseUtils.commitMessage(raw, 0);
if (b < 0)
return RawCharSequence.EMPTY;
return new RawCharSequence(raw, b, raw.length);
}
private static class PatternSearch extends PatternMatchRevFilter {View on GitHub (pinned to d44925c47c)
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 ""
Example fix
// before
RevFilter f = MessageRevFilter.create(pattern);
// after
if (pattern == null || pattern.trim().isEmpty()) {
return RevFilter.ALL; // or don't add the filter
}
RevFilter f = MessageRevFilter.create(pattern); Defensive patterns
Strategy: validation
Validate before calling
String p = userInput == null ? "" : userInput.trim();
if (p.isEmpty()) { throw new IllegalArgumentException("message pattern must not be empty"); } Type guard
boolean validPattern(String s) { return s != null && !s.trim().isEmpty(); } Try / catch
try {
RevFilter f = MessageRevFilter.create(pattern);
} catch (IllegalArgumentException e) {
// skip the message filter or report empty search input
} Prevention
- Validate search terms before building commit filters
- Represent missing criteria as null/Optional, not ""
- Cover empty-input paths in UI/CLI validation
When it happens
Trigger: Calling MessageRevFilter.create("") — e.g. an empty search box value or defaulted config string passed to the factory.
Common situations: Commit message search features that don't validate input; log-parsing scripts where the pattern variable came out empty after tokenizing arguments.
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/223c48f4abf012d7.
Report an issue: GitHub.