theonedev/onedev · error · RuntimeException

Malformed query

Error message

Malformed query

What it means

PullRequestQuery parsing installs an ANTLR BaseErrorListener on the lexer that converts any lexical/parse error into RuntimeException("Malformed query", e). This means the query string did not conform to OneDev's pull request query grammar (bad token, unclosed quote, unknown operator spelling).

Source

Thrown at server-core/src/main/java/io/onedev/server/search/entity/pullrequest/PullRequestQuery.java:122

	public PullRequestQuery(@Nullable Criteria<PullRequest> criteria) {
		this(criteria, new ArrayList<>());
	}

	public PullRequestQuery() {
		this(null);
	}

	public static PullRequestQuery parse(@Nullable Project project, @Nullable String queryString, boolean withCurrentUserCriteria) {
		if (queryString != null) {
			CharStream is = CharStreams.fromString(queryString);
			PullRequestQueryLexer lexer = new PullRequestQueryLexer(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);
			PullRequestQueryParser parser = new PullRequestQueryParser(tokens);
			parser.removeErrorListeners();
			parser.setErrorHandler(new BailErrorStrategy());
			QueryContext queryContext = parser.query();
			CriteriaContext criteriaContext = queryContext.criteria();
			Criteria<PullRequest> requestCriteria;
			if (criteriaContext != null) {
				requestCriteria = new PullRequestQueryBaseVisitor<Criteria<PullRequest>>() {

					@Override
					public Criteria<PullRequest> visitReferenceCriteria(ReferenceCriteriaContext ctx) {
						return new ReferenceCriteria(null, ctx.getText(), Is);
					}

View on GitHub (pinned to d44925c47c)

Solutions

  1. Validate/correct the query syntax against OneDev's pull request query grammar (test it in the web UI query editor first).
  2. Escape quotes and special characters in values; balance all quotes and parentheses.
  3. Build queries with the criteria API or copy a working query from the UI instead of hand-writing tokens.

Example fix

// before
PullRequestQuery.parse("to is \"alice); // unbalanced quote -> Malformed query
// after
PullRequestQuery.parse("\"to\" is \"alice\"");
Defensive patterns

Strategy: validation

Validate before calling

function validateQuery(q) {
  if (!balancedQuotes(q) || !balancedParens(q)) throw new Error('Malformed query');
  return q;
}

Type guard

function isWellFormedQuery(q) { return typeof q === 'string' && q.split('"').length % 2 === 1; }

Try / catch

try { query = PullRequestQuery.parse(userQuery); } catch (RuntimeException e) { if (e.getMessage().equals("Malformed query")) { showQuerySyntaxHelp(userQuery); } else throw e; }

Prevention

When it happens

Trigger: Passing a syntactically invalid pull request query string to PullRequestQuery.parse, e.g. 'to is "alice (unbalanced quote)', unknown criterion keyword, stray characters, or wrong operator syntax.

Common situations: Hand-written query strings in REST calls or saved queries, typos in field names, quotes/special characters not escaped, queries built by string concatenation without validation.

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/37b7b10a2e0bbf49. Report an issue: GitHub.