{"record":{"id":"98424710b6990d4d","repo":"theonedev/onedev","slug":"malformed-query-984247","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/issue/IssueQuery.java","lineNumber":162,"sourceCode":"\t\tthis(criteria, new ArrayList<>());\n\t}\n\n\tpublic IssueQuery() {\n\t\tthis(null);\n\t}\n\n\tpublic static IssueQuery parse(@Nullable Project project, @Nullable String queryString,\n\t\t\t\t\t\t\t\t   IssueQueryParseOption option, boolean validate) {\n\t\tif (queryString != null) {\n\t\t\tCharStream is = CharStreams.fromString(queryString);\n\t\t\tIssueQueryLexer lexer = new IssueQueryLexer(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\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\n\t\t\t});\n\t\t\tCommonTokenStream tokens = new CommonTokenStream(lexer);\n\t\t\tIssueQueryParser parser = new IssueQueryParser(tokens);\n\t\t\tparser.removeErrorListeners();\n\t\t\tparser.setErrorHandler(new BailErrorStrategy());\n\n\t\t\tQueryContext queryContext = parser.query();\n\t\t\tCriteriaContext criteriaContext = queryContext.criteria();\n\t\t\tCriteria<Issue> issueCriteria;\n\t\t\tif (criteriaContext != null) {\n\t\t\t\tissueCriteria = new IssueQueryBaseVisitor<Criteria<Issue>>() {\n\n\t\t\t\t\tprivate long getValueOrdinal(ChoiceField field, String value) {\n\t\t\t\t\t\tList<String> choices = new ArrayList<>(field.getChoiceProvider().getChoices(true).keySet());\n\t\t\t\t\t\treturn choices.indexOf(value);\n\t\t\t\t\t}","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/IssueQuery.java#L144-L180","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n\"text ~ \\\"foo\"   // unbalanced quote -> Malformed query\n// after\n\"text ~ \\\"foo\\\"\"","handlingStrategy":"try-catch","validationCode":"// pre-check: balanced quotes and no obviously illegal chars\nif (q.chars().filter(c -> c == '\"').count() % 2 != 0)\n    throw new IllegalArgumentException(\"Unbalanced quotes in query\");","typeGuard":null,"tryCatchPattern":"try {\n    IssueQuery query = IssueQuery.parse(project, q);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Malformed query\")) {\n        // show user-friendly parse error\n    } else {\n        throw e;\n    }\n}","preventionTips":["Validate query strings before saving/persisting","Escape quotes in free-text values","Test user-typed queries against the grammar in UI validation"],"tags":["query","parser","syntax"],"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"}