theonedev/onedev · error · RuntimeException
Malformed query
Error message
Malformed query
What it means
IssueQuery.parse uses an ANTLR lexer/parser with a BaseErrorListener that converts any lexer syntax error into a RuntimeException('Malformed query'). This means the query text could not even be tokenized per the IssueQuery grammar — an illegal character or malformed token appears before parsing rules run.
Source
Thrown at server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java:162
this(criteria, new ArrayList<>());
}
public IssueQuery() {
this(null);
}
public static IssueQuery parse(@Nullable Project project, @Nullable String queryString,
IssueQueryParseOption option, boolean validate) {
if (queryString != null) {
CharStream is = CharStreams.fromString(queryString);
IssueQueryLexer lexer = new IssueQueryLexer(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);
IssueQueryParser parser = new IssueQueryParser(tokens);
parser.removeErrorListeners();
parser.setErrorHandler(new BailErrorStrategy());
QueryContext queryContext = parser.query();
CriteriaContext criteriaContext = queryContext.criteria();
Criteria<Issue> issueCriteria;
if (criteriaContext != null) {
issueCriteria = new IssueQueryBaseVisitor<Criteria<Issue>>() {
private long getValueOrdinal(ChoiceField field, String value) {
List<String> choices = new ArrayList<>(field.getChoiceProvider().getChoices(true).keySet());
return choices.indexOf(value);
}View on GitHub (pinned to d44925c47c)
Solutions
- Fix the query syntax: balance quotes, remove or escape illegal characters, and use only grammar-supported operators
- Catch the RuntimeException and surface a user-friendly parse error rather than a stack trace
- Pre-validate the query with a try-parse before persisting it as a saved query
Example fix
// before "text ~ \"foo" // unbalanced quote -> Malformed query // after "text ~ \"foo\""
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check: balanced quotes and no obviously illegal chars
if (q.chars().filter(c -> c == '"').count() % 2 != 0)
throw new IllegalArgumentException("Unbalanced quotes in query"); Try / catch
try {
IssueQuery query = IssueQuery.parse(project, q);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("Malformed query")) {
// show user-friendly parse error
} else {
throw e;
}
} Prevention
- Validate query strings before saving/persisting
- Escape quotes in free-text values
- Test user-typed queries against the grammar in UI validation
When it happens
Trigger: Passing a query string containing characters illegal in the issue query lexer (unbalanced quotes, stray characters like '!', unescaped symbols) to IssueQuery.parse or a query field with that text.
Common situations: Typing a free-text search with special characters not supported by the grammar; copying queries with smart quotes; unbalanced '"' in field values; API callers submitting user-typed query strings unvalidated.
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/98424710b6990d4d.
Report an issue: GitHub.