{"record":{"id":"55eacfbce4695444","repo":"theonedev/onedev","slug":"malformed-query-55eacf","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/project/ProjectQuery.java","lineNumber":93,"sourceCode":"\tpublic ProjectQuery(@Nullable Criteria<Project> criteria) {\n\t\tthis(criteria, new ArrayList<>());\n\t}\n\t\n\tpublic ProjectQuery() {\n\t\tthis(null);\n\t}\n\t\n\tpublic static ProjectQuery parse(@Nullable String queryString) {\n\t\tif (queryString != null) {\n\t\t\tCharStream is = CharStreams.fromString(queryString); \n\t\t\tProjectQueryLexer lexer = new ProjectQueryLexer(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\tProjectQueryParser parser = new ProjectQueryParser(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<Project> projectCriteria;\n\t\t\tif (criteriaContext != null) {\n\t\t\t\tprojectCriteria = new ProjectQueryBaseVisitor<Criteria<Project>>() {\n\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic Criteria<Project> 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":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/project/ProjectQuery.java#L75-L111","documentation":"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).","triggerScenarios":"Calling ProjectQuery.parse / parseProjectQuery with a syntactically invalid query string, e.g. unbalanced quotes, stray characters, or an unrecognized criterion token.","commonSituations":"Hand-written saved queries pasted into REST calls; programmatic query construction with unescaped values; query text from older OneDev versions using removed syntax.","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."],"exampleFix":"// before\nProjectQuery.parse(\"name = my project\"); // unquoted value -> Malformed query\n// after\nProjectQuery.parse(\"\\\"name\\\" == \\\"my project\\\"\");","handlingStrategy":"validation","validationCode":"// validate quotes balance before parsing\nlong quotes = queryText.chars().filter(c -> c == '\"').count();\nif (quotes % 2 != 0) throw new IllegalArgumentException(\"Unbalanced quotes in query\");","typeGuard":"null","tryCatchPattern":"try { q = ProjectQuery.parse(text); } catch (RuntimeException e) { showInvalidQuery(e.getCause()); }","preventionTips":["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"],"tags":["parsing","query","antlr"],"backgroundTag":"invalid-query-parameter","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}