{"record":{"id":"e29ff7c5bcd234e2","repo":"theonedev/onedev","slug":"malformed-query-e29ff7","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/workspace/WorkspaceQuery.java","lineNumber":103,"sourceCode":"\tpublic static WorkspaceQuery parse(@Nullable String queryString) {\n\t\treturn parse(null, queryString, false);\n\t}\n\n\tpublic static WorkspaceQuery parse(@Nullable Project project, @Nullable String queryString) {\n\t\treturn parse(project, queryString, false);\n\t}\n\n\tpublic static WorkspaceQuery 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\tWorkspaceQueryLexer lexer = new WorkspaceQueryLexer(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\n\t\t\t});\n\t\t\tCommonTokenStream tokens = new CommonTokenStream(lexer);\n\t\t\tWorkspaceQueryParser parser = new WorkspaceQueryParser(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<Workspace> workspaceCriteria;\n\t\t\tif (criteriaContext != null) {\n\t\t\t\tworkspaceCriteria = new WorkspaceQueryBaseVisitor<Criteria<Workspace>>() {\n\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic Criteria<Workspace> visitOperatorCriteria(OperatorCriteriaContext ctx) {\n\t\t\t\t\t\tswitch (ctx.operator.getType()) {\n\t\t\t\t\t\tcase Pending:\n\t\t\t\t\t\t\treturn new PendingCriteria();","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/workspace/WorkspaceQuery.java#L85-L121","documentation":"WorkspaceQuery.parse feeds the query text through an ANTLR lexer/parser with error listeners installed; any lexical or syntactic error is converted to a RuntimeException with message 'Malformed query'. It signals the query string does not conform to the workspace query grammar.","triggerScenarios":"Calling WorkspaceQuery.parse with text containing unbalanced quotes, invalid operators, bad ordering syntax, or unrecognized tokens.","commonSituations":"Hand-written query with a stray quote or keyword; programmatic query construction concatenating strings incorrectly; pasting queries from docs for a different entity type.","solutions":["Validate the query text against the workspace query grammar (balanced quotes, valid operators, valid order clauses).","Wrap parse() in try-catch and surface the raw query back to the user for correction.","Test the query interactively in the OneDev UI query editor before hardcoding it."],"exampleFix":"// before\nvar query = WorkspaceQuery.parse(\"name ~ 'foo\"); // unbalanced quote\n// after\nvar query = WorkspaceQuery.parse(\"name ~ \\\"foo\\\"\");","handlingStrategy":"try-catch","validationCode":"if (queryText.chars().filter(c -> c == '\"').count() % 2 != 0) throw new IllegalArgumentException(\"Unbalanced quotes in query\");","typeGuard":null,"tryCatchPattern":"try {\n    var query = WorkspaceQuery.parse(queryText);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Malformed query\")) {\n        // show queryText to user for correction\n    } else throw e;\n}","preventionTips":["Validate queries in the UI query editor before persisting","Escape quotes properly when building queries programmatically","Use a query builder instead of string concatenation"],"tags":["antlr","parser","query"],"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-14T05:17:10.506Z"}