theonedev/onedev · error · RuntimeException
Malformed query
Error message
Malformed query
What it means
ProjectQuery.parse wires ANTLR lexer/parser with error listeners that convert any lexer or parser syntax error into a RuntimeException('Malformed query'). It means the supplied project query string does not match the query grammar (bad token, missing quotes, unknown keyword).
Source
Thrown at server-core/src/main/java/io/onedev/server/search/entity/project/ProjectQuery.java:93
public ProjectQuery(@Nullable Criteria<Project> criteria) {
this(criteria, new ArrayList<>());
}
public ProjectQuery() {
this(null);
}
public static ProjectQuery parse(@Nullable String queryString) {
if (queryString != null) {
CharStream is = CharStreams.fromString(queryString);
ProjectQueryLexer lexer = new ProjectQueryLexer(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);
ProjectQueryParser parser = new ProjectQueryParser(tokens);
parser.removeErrorListeners();
parser.setErrorHandler(new BailErrorStrategy());
QueryContext queryContext = parser.query();
CriteriaContext criteriaContext = queryContext.criteria();
Criteria<Project> projectCriteria;
if (criteriaContext != null) {
projectCriteria = new ProjectQueryBaseVisitor<Criteria<Project>>() {
@Override
public Criteria<Project> visitFuzzyCriteria(FuzzyCriteriaContext ctx) {
return new FuzzyCriteria(getValue(ctx.getText()));
}
View on GitHub (pinned to d44925c47c)
Solutions
- Validate/escape the query string: quote field values with double quotes and escape embedded quotes.
- Simplify the query and add tokens back incrementally to find the offending part.
- Check the grammar/keyword list (ProjectQueryLexer rule names) for supported operators.
- Catch RuntimeException from parse and show a user-facing 'malformed query' message with the original cause.
Example fix
// before
ProjectQuery.parse("name = my project"); // unquoted value -> Malformed query
// after
ProjectQuery.parse("\"name\" == \"my project\""); Defensive patterns
Strategy: validation
Validate before calling
// validate quotes balance before parsing
long quotes = queryText.chars().filter(c -> c == '"').count();
if (quotes % 2 != 0) throw new IllegalArgumentException("Unbalanced quotes in query"); Type guard
null
Try / catch
try { q = ProjectQuery.parse(text); } catch (RuntimeException e) { showInvalidQuery(e.getCause()); } Prevention
- Always double-quote values containing spaces
- Build queries via a query builder rather than string concatenation
- Test saved queries after OneDev upgrades
- Escape embedded double quotes in values
When it happens
Trigger: Calling ProjectQuery.parse / parseProjectQuery with a syntactically invalid query string, e.g. unbalanced quotes, stray characters, or an unrecognized criterion token.
Common situations: Hand-written saved queries pasted into REST calls; programmatic query construction with unescaped values; query text from older OneDev versions using removed syntax.
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/55eacfbce4695444.
Report an issue: GitHub.