theonedev/onedev · error · RuntimeException

Malformed query

Error message

Malformed query

What it means

CommitQuery.parse uses an ANTLR lexer for the commit query grammar and installs an error listener that converts any lexer syntax error into a RuntimeException('Malformed query', cause). It signals that the query string could not be tokenized against the commit query grammar at all.

Source

Thrown at server-core/src/main/java/io/onedev/server/search/commit/CommitQuery.java:61

		return criterias;
	}

	public void setCriterias(List<CommitCriteria> criterias) {
		this.criterias = criterias;
	}

	public static CommitQuery parse(Project project, @Nullable String queryString, boolean withCurrentUserCriteria) {
		List<CommitCriteria> criterias = new ArrayList<>();
		if (queryString != null) {
			CharStream is = CharStreams.fromString(queryString); 
			CommitQueryLexer lexer = new CommitQueryLexer(is);
			lexer.removeErrorListeners();
			lexer.addErrorListener(new BaseErrorListener() {

				@Override
				public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
						int charPositionInLine, String msg, RecognitionException e) {
					throw new RuntimeException("Malformed query", e);
				}
				
			});
			CommonTokenStream tokens = new CommonTokenStream(lexer);
			CommitQueryParser parser = new CommitQueryParser(tokens);
			parser.removeErrorListeners();
			parser.setErrorHandler(new BailErrorStrategy());
			
			Map<Class<? extends CommitCriteria>, List<Object>> criteriaValues = new LinkedHashMap<>();
			
			for (CriteriaContext criteria: parser.query().criteria()) {
				if (criteria.authorCriteria() != null) {
					if (criteria.authorCriteria().AuthoredByMe() != null) {
						if (!withCurrentUserCriteria)
							throw new ExplicitException("Criteria '" + criteria.authorCriteria().AuthoredByMe().getText() + "' is not supported here");
							criteriaValues.computeIfAbsent(AuthorCriteria.class, k->new ArrayList<>()).add(null);
					} else {
						for (var value: criteria.authorCriteria().Value())

View on GitHub (pinned to d44925c47c)

Solutions

  1. Fix the query string syntax: balance quotes/parentheses and remove illegal characters.
  2. Use only grammar-supported criteria syntax (e.g. 'author(me) and message(foo)').
  3. Catch the RuntimeException (check message/cause) at the parse call site and surface 'malformed query' to the user with the offending input echoed back.

Example fix

// before
CommitQuery.parse(project, "author:'unclosed, false);
// after
CommitQuery.parse(project, "author(\"unclosed\")", false);
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate: balanced quotes/parens and allowed characters
if (s.chars().filter(c -> c == '"').count() % 2 != 0)
    throw new IllegalArgumentException("Unbalanced quotes in commit query");

Try / catch

try {
    return CommitQuery.parse(project, queryString, withUser);
} catch (RuntimeException e) {
    if ("Malformed query".equals(e.getMessage()))
        throw new UserFriendlyException("Malformed commit query: " + queryString);
    throw e;
}

Prevention

When it happens

Trigger: Passing a syntactically invalid commit query string (unbalanced quotes/parens, illegal characters, e.g. 'author:"unclosed') to CommitQuery.parse so the lexer's syntaxError callback fires.

Common situations: Hand-typed commit search strings with typos; programmatic query construction with unescaped characters; copy-pasted queries containing curly quotes or stray characters the lexer rejects.

Understand the failure class

Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.

Related errors


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