theonedev/onedev · error · IllegalArgumentException

Cannot match on empty string.

Error message

Cannot match on empty string.

What it means

AuthorRevFilter.create(String) throws IllegalArgumentException when the pattern is the empty string. An empty regex or substring would match every commit author, which is almost certainly a caller bug, so JGit rejects it eagerly.

Source

Thrown at server-core/src/main/java/org/eclipse/jgit/revwalk/filter/AuthorRevFilter.java:41

public class AuthorRevFilter {
	/**
	 * Create a new author 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 AuthorRevFilter() {
		// Don't permit us to be created.
	}

	static RawCharSequence textFor(RevCommit cmit) {
		final byte[] raw = cmit.getRawBuffer();
		final int b = RawParseUtils.author(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

  1. Validate the pattern is non-empty before calling create and skip filter creation (use RevFilter.NONE or no filter) when empty
  2. Trim user input first; treat whitespace-only as empty and reject or ignore
  3. In UI/CLI layers, require the search field to be non-blank before constructing the filter

Example fix

// before
RevFilter f = AuthorRevFilter.create(userInput);
// after
if (userInput == null || userInput.trim().isEmpty()) {
    throw new IllegalArgumentException("author pattern must not be empty");
}
RevFilter f = AuthorRevFilter.create(userInput);
Defensive patterns

Strategy: validation

Validate before calling

String p = userInput == null ? "" : userInput.trim();
if (p.isEmpty()) { throw new IllegalArgumentException("author pattern must not be empty"); }

Type guard

boolean validPattern(String s) { return s != null && !s.trim().isEmpty(); }

Try / catch

try {
    RevFilter f = AuthorRevFilter.create(pattern);
} catch (IllegalArgumentException e) {
    // fall back: no author filter or report empty search term to user
}

Prevention

When it happens

Trigger: Calling AuthorRevFilter.create("") — typically when a user-supplied search string was empty or the variable was never populated.

Common situations: CLI/git-swing search boxes passed through without trimming or emptiness checks; config values defaulting to empty string instead of null meaning 'no filter'.

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


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/36a68967b6dbd918. Report an issue: GitHub.