theonedev/onedev · error · RuntimeException
Malformed query
Error message
Malformed query
What it means
AgentQuery parsing installs an ANTLR BaseErrorListener on the lexer; any lexical error in the query text (illegal characters, unclosed quotes) makes the listener throw RuntimeException('Malformed query', cause).
Source
Thrown at server-core/src/main/java/io/onedev/server/search/entity/agent/AgentQuery.java:82
public AgentQuery(@Nullable Criteria<Agent> criteria) {
this(criteria, new ArrayList<>());
}
public AgentQuery() {
this(null);
}
public static AgentQuery parse(@Nullable String queryString, boolean forRunner) {
if (queryString != null) {
CharStream is = CharStreams.fromString(queryString);
AgentQueryLexer lexer = new AgentQueryLexer(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);
AgentQueryParser parser = new AgentQueryParser(tokens);
parser.removeErrorListeners();
parser.setErrorHandler(new BailErrorStrategy());
QueryContext queryContext = parser.query();
CriteriaContext criteriaContext = queryContext.criteria();
Criteria<Agent> agentCriteria;
if (criteriaContext != null) {
agentCriteria = new AgentQueryBaseVisitor<Criteria<Agent>>() {
@Override
public Criteria<Agent> visitFuzzyCriteria(FuzzyCriteriaContext ctx) {
return new FuzzyCriteria(getValue(ctx.getText()));
}
View on GitHub (pinned to d44925c47c)
Solutions
- Fix the query syntax: balance quotes and remove illegal characters
- Build queries programmatically via the criteria/sort API instead of raw strings
- Catch RuntimeException around query parsing to surface a user-friendly message
Example fix
// before
new AgentQuery("status is "running"") // unbalanced quote
// after
new AgentQuery("status is \"running\"") Defensive patterns
Strategy: try-catch
Validate before calling
if (q.chars().filter(c -> c == '"').count() % 2 != 0) throw new IllegalArgumentException("unbalanced quotes in query"); Try / catch
try { new AgentQuery(q, forRunner); } catch (RuntimeException e) { /* show 'malformed query' with original input */ } Prevention
- Escape quotes when building query strings programmatically
- Validate syntax in a form/preview before persisting queries
- Test queries interactively in the web UI before automating them
When it happens
Trigger: Passing an agent query string with invalid tokens — e.g. unbalanced quotes, stray characters like ';' or '&&', or unsupported syntax — to AgentQuery for parsing.
Common situations: Building the query programmatically without escaping; hand-editing a saved query; copying a query from another entity type whose syntax differs.
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Error parsing query
- Criteria '' is not supported here
- Unexpected operator:
- Cannot order by field:
- Attribute not found:
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/f6b86acfa2fb8f66.
Report an issue: GitHub.