theonedev/onedev · error · RuntimeException

"Malformed query"

Error message

"Malformed query"

What it means

WorkspaceQuery.parse feeds the query text through an ANTLR lexer/parser with error listeners installed; any lexical or syntactic error is converted to a RuntimeException with message 'Malformed query'. It signals the query string does not conform to the workspace query grammar.

Solutions

  1. Validate the query text against the workspace query grammar (balanced quotes, valid operators, valid order clauses).
  2. Wrap parse() in try-catch and surface the raw query back to the user for correction.
  3. Test the query interactively in the OneDev UI query editor before hardcoding it.

Example fix

// before
var query = WorkspaceQuery.parse("name ~ 'foo"); // unbalanced quote
// after
var query = WorkspaceQuery.parse("name ~ \"foo\"");
Defensive patterns

Strategy: try-catch

Validate before calling

if (queryText.chars().filter(c -> c == '"').count() % 2 != 0) throw new IllegalArgumentException("Unbalanced quotes in query");

Try / catch

try {
    var query = WorkspaceQuery.parse(queryText);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().contains("Malformed query")) {
        // show queryText to user for correction
    } else throw e;
}

Prevention

When it happens

Trigger: Calling WorkspaceQuery.parse with text containing unbalanced quotes, invalid operators, bad ordering syntax, or unrecognized tokens.

Common situations: Hand-written query with a stray quote or keyword; programmatic query construction concatenating strings incorrectly; pasting queries from docs for a different entity type.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at server-core/src/main/java/io/onedev/server/search/entity/workspace/WorkspaceQuery.java:103

	public static WorkspaceQuery parse(@Nullable String queryString) {
		return parse(null, queryString, false);
	}

	public static WorkspaceQuery parse(@Nullable Project project, @Nullable String queryString) {
		return parse(project, queryString, false);
	}

	public static WorkspaceQuery parse(@Nullable Project project, @Nullable String queryString, boolean withCurrentUserCriteria) {
		if (queryString != null) {
			CharStream is = CharStreams.fromString(queryString);
			WorkspaceQueryLexer lexer = new WorkspaceQueryLexer(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);
			WorkspaceQueryParser parser = new WorkspaceQueryParser(tokens);
			parser.removeErrorListeners();
			parser.setErrorHandler(new BailErrorStrategy());
			QueryContext queryContext = parser.query();
			CriteriaContext criteriaContext = queryContext.criteria();
			Criteria<Workspace> workspaceCriteria;
			if (criteriaContext != null) {
				workspaceCriteria = new WorkspaceQueryBaseVisitor<Criteria<Workspace>>() {

					@Override
					public Criteria<Workspace> visitOperatorCriteria(OperatorCriteriaContext ctx) {
						switch (ctx.operator.getType()) {
						case Pending:
							return new PendingCriteria();

View on GitHub (pinned to d44925c47c)