{"record":{"id":"d9f8d6db9da37268","repo":"theonedev/onedev","slug":"malformed-query-d9f8d6","errorCode":null,"errorMessage":"Malformed query","messagePattern":"Malformed query","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/commit/CommitQuery.java","lineNumber":61,"sourceCode":"\t\treturn criterias;\n\t}\n\n\tpublic void setCriterias(List<CommitCriteria> criterias) {\n\t\tthis.criterias = criterias;\n\t}\n\n\tpublic static CommitQuery parse(Project project, @Nullable String queryString, boolean withCurrentUserCriteria) {\n\t\tList<CommitCriteria> criterias = new ArrayList<>();\n\t\tif (queryString != null) {\n\t\t\tCharStream is = CharStreams.fromString(queryString); \n\t\t\tCommitQueryLexer lexer = new CommitQueryLexer(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\tCommitQueryParser parser = new CommitQueryParser(tokens);\n\t\t\tparser.removeErrorListeners();\n\t\t\tparser.setErrorHandler(new BailErrorStrategy());\n\t\t\t\n\t\t\tMap<Class<? extends CommitCriteria>, List<Object>> criteriaValues = new LinkedHashMap<>();\n\t\t\t\n\t\t\tfor (CriteriaContext criteria: parser.query().criteria()) {\n\t\t\t\tif (criteria.authorCriteria() != null) {\n\t\t\t\t\tif (criteria.authorCriteria().AuthoredByMe() != null) {\n\t\t\t\t\t\tif (!withCurrentUserCriteria)\n\t\t\t\t\t\t\tthrow new ExplicitException(\"Criteria '\" + criteria.authorCriteria().AuthoredByMe().getText() + \"' is not supported here\");\n\t\t\t\t\t\t\tcriteriaValues.computeIfAbsent(AuthorCriteria.class, k->new ArrayList<>()).add(null);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfor (var value: criteria.authorCriteria().Value())","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/commit/CommitQuery.java#L43-L79","documentation":"CommitQuery.parse uses an ANTLR lexer for the commit query grammar and installs an error listener that converts any lexer syntax error into a RuntimeException('Malformed query', cause). It signals that the query string could not be tokenized against the commit query grammar at all.","triggerScenarios":"Passing a syntactically invalid commit query string (unbalanced quotes/parens, illegal characters, e.g. 'author:\"unclosed') to CommitQuery.parse so the lexer's syntaxError callback fires.","commonSituations":"Hand-typed commit search strings with typos; programmatic query construction with unescaped characters; copy-pasted queries containing curly quotes or stray characters the lexer rejects.","solutions":["Fix the query string syntax: balance quotes/parentheses and remove illegal characters.","Use only grammar-supported criteria syntax (e.g. 'author(me) and message(foo)').","Catch the RuntimeException (check message/cause) at the parse call site and surface 'malformed query' to the user with the offending input echoed back."],"exampleFix":"// before\nCommitQuery.parse(project, \"author:'unclosed, false);\n// after\nCommitQuery.parse(project, \"author(\\\"unclosed\\\")\", false);","handlingStrategy":"try-catch","validationCode":"// pre-validate: balanced quotes/parens and allowed characters\nif (s.chars().filter(c -> c == '\"').count() % 2 != 0)\n    throw new IllegalArgumentException(\"Unbalanced quotes in commit query\");","typeGuard":null,"tryCatchPattern":"try {\n    return CommitQuery.parse(project, queryString, withUser);\n} catch (RuntimeException e) {\n    if (\"Malformed query\".equals(e.getMessage()))\n        throw new UserFriendlyException(\"Malformed commit query: \" + queryString);\n    throw e;\n}","preventionTips":["Escape quotes and special characters in programmatically built queries","Use the query builder UI instead of hand-written strings where possible","Trim/copy-paste artifacts (smart quotes, line breaks) before parsing"],"tags":["antlr","parsing","commit-search"],"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"}