{"record":{"id":"f6b86acfa2fb8f66","repo":"theonedev/onedev","slug":"malformed-query-f6b86a","errorCode":null,"errorMessage":"Malformed query","messagePattern":"Malformed query","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/agent/AgentQuery.java","lineNumber":82,"sourceCode":"\tpublic AgentQuery(@Nullable Criteria<Agent> criteria) {\n\t\tthis(criteria, new ArrayList<>());\n\t}\n\n\tpublic AgentQuery() {\n\t\tthis(null);\n\t}\n\t\n\tpublic static AgentQuery parse(@Nullable String queryString, boolean forRunner) {\n\t\tif (queryString != null) {\n\t\t\tCharStream is = CharStreams.fromString(queryString); \n\t\t\tAgentQueryLexer lexer = new AgentQueryLexer(is);\n\t\t\tlexer.removeErrorListeners();\n\t\t\tlexer.addErrorListener(new BaseErrorListener() {\n\n\t\t\t\t@Override\n\t\t\t\tpublic void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,\n\t\t\t\t\t\tint charPositionInLine, String msg, RecognitionException e) {\n\t\t\t\t\tthrow new RuntimeException(\"Malformed query\", e);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t});\n\t\t\tCommonTokenStream tokens = new CommonTokenStream(lexer);\n\t\t\tAgentQueryParser parser = new AgentQueryParser(tokens);\n\t\t\tparser.removeErrorListeners();\n\t\t\tparser.setErrorHandler(new BailErrorStrategy());\n\t\t\tQueryContext queryContext = parser.query();\n\t\t\tCriteriaContext criteriaContext = queryContext.criteria();\n\t\t\tCriteria<Agent> agentCriteria;\n\t\t\tif (criteriaContext != null) {\n\t\t\t\tagentCriteria = new AgentQueryBaseVisitor<Criteria<Agent>>() {\n\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic Criteria<Agent> visitFuzzyCriteria(FuzzyCriteriaContext ctx) {\n\t\t\t\t\t\treturn new FuzzyCriteria(getValue(ctx.getText()));\n\t\t\t\t\t}\n\t\t\t\t\t","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/agent/AgentQuery.java#L64-L100","documentation":"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).","triggerScenarios":"Passing an agent query string with invalid tokens — e.g. unbalanced quotes, stray characters like ';' or '&&', or unsupported syntax — to AgentQuery for parsing.","commonSituations":"Building the query programmatically without escaping; hand-editing a saved query; copying a query from another entity type whose syntax differs.","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"],"exampleFix":"// before\nnew AgentQuery(\"status is \"running\"\") // unbalanced quote\n// after\nnew AgentQuery(\"status is \\\"running\\\"\")","handlingStrategy":"try-catch","validationCode":"if (q.chars().filter(c -> c == '\"').count() % 2 != 0) throw new IllegalArgumentException(\"unbalanced quotes in query\");","typeGuard":null,"tryCatchPattern":"try { new AgentQuery(q, forRunner); } catch (RuntimeException e) { /* show 'malformed query' with original input */ }","preventionTips":["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"],"tags":["antlr","query-syntax","onedev"],"backgroundTag":"schema-validation-failed","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}