{"record":{"id":"7eb3081e6086c476","repo":"theonedev/onedev","slug":"malformed-query-7eb308","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/pack/PackQuery.java","lineNumber":81,"sourceCode":"\tpublic PackQuery(@Nullable Criteria<Pack> criteria) {\n\t\tsuper(criteria, new ArrayList<>());\n\t}\n\t\n\tpublic PackQuery() {\n\t\tsuper(null, new ArrayList<>());\n\t}\n\t\n\tpublic static PackQuery parse(@Nullable Project project, @Nullable String queryString, boolean withCurrentUserCriteria) {\n\t\tif (queryString != null) {\n\t\t\tCharStream is = CharStreams.fromString(queryString); \n\t\t\tPackQueryLexer lexer = new PackQueryLexer(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\tPackQueryParser parser = new PackQueryParser(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<Pack> packCriteria;\n\t\t\tif (criteriaContext != null) {\n\t\t\t\tpackCriteria = new PackQueryBaseVisitor<Criteria<Pack>>() {\n\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic Criteria<Pack> 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":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/pack/PackQuery.java#L63-L99","documentation":"PackQuery.parse lexes and parses the pack query string with an ANTLR lexer/parser. Both are configured with a BaseErrorListener that converts any ANTLR syntax error into a RuntimeException('Malformed query', e), so an unparseable query text surfaces as this error.","triggerScenarios":"Calling PackQuery.parse with a query string that violates the pack query grammar — unbalanced quotes/parentheses, unknown tokens, invalid operator placement, or trailing garbage.","commonSituations":"Hand-written query strings in saved queries or API calls; queries built by string concatenation without escaping; users typing free-text search into a structured query field; grammar changes between OneDev versions making old queries invalid.","solutions":["Fix the query syntax per pack query grammar (quote values, correct operators, balanced parens)","Simplify the query and re-add clauses until the offending part is found","Validate the query in the UI query editor which reports parse problems before saving","Catch the RuntimeException and surface e's ANTLR message to locate the offending token"],"exampleFix":"// before\nPackQuery.parse(project, \"published by \"me\"\") // broken quoting\n// after\nPackQuery.parse(project, \"\\\"published by\\\" \\\"me\\\"\") // correctly quoted per grammar","handlingStrategy":"try-catch","validationCode":"function validatePackQuery(q) { const tokens = q.match(/\"[^\"]*\"|\\S+/g); if (!tokens) throw new Error('empty query'); const open = (q.match(/\\(/g)||[]).length, close = (q.match(/\\)/g)||[]).length; if (open !== close) throw new Error('unbalanced parens'); }","typeGuard":"null","tryCatchPattern":"try { query = PackQuery.parse(project, q); } catch (RuntimeException e) { log.warn(\"Malformed pack query: {}\", q, e); throw new UserInputError(\"Invalid pack query syntax\"); }","preventionTips":["Validate queries in the UI query editor before saving","Escape quotes in values and keep parentheses balanced","Build queries via the query builder API instead of string concatenation","Test queries after upgrading OneDev (grammar may change)"],"tags":["query","syntax","antlr","onedev"],"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"}