{"record":{"id":"69e86cc4449e8704","repo":"theonedev/onedev","slug":"unexpected-operator-69e86c","errorCode":null,"errorMessage":"Unexpected operator: ","messagePattern":"Unexpected operator: ","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/codecomment/CodeCommentQuery.java","lineNumber":136,"sourceCode":"\t\t\t\t\t\tswitch (ctx.operator.getType()) {\n\t\t\t\t\t\t\tcase Resolved:\n\t\t\t\t\t\t\t\treturn new ResolvedCriteria();\n\t\t\t\t\t\t\tcase Unresolved:\n\t\t\t\t\t\t\t\treturn new UnresolvedCriteria();\n\t\t\t\t\t\t\tcase MentionedMe:\n\t\t\t\t\t\t\t\tif (!withCurrentUserCriteria)\n\t\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Criteria '\" + ctx.operator.getText() + \"' is not supported here\");\n\t\t\t\t\t\t\t\treturn new MentionedMeCriteria();\n\t\t\t\t\t\t\tcase CreatedByMe:\n\t\t\t\t\t\t\t\tif (!withCurrentUserCriteria)\n\t\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Criteria '\" + ctx.operator.getText() + \"' is not supported here\");\n\t\t\t\t\t\t\t\treturn new CreatedByMeCriteria();\n\t\t\t\t\t\t\tcase RepliedByMe:\n\t\t\t\t\t\t\t\tif (!withCurrentUserCriteria)\n\t\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Criteria '\" + ctx.operator.getText() + \"' is not supported here\");\n\t\t\t\t\t\t\t\treturn new RepliedByMeCriteria();\n\t\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Unexpected operator: \" + ctx.operator.getText());\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic Criteria<CodeComment> visitOperatorValueCriteria(OperatorValueCriteriaContext ctx) {\n\t\t\t\t\t\tint operator = ctx.operator.getType();\n\t\t\t\t\t\tvar criterias = new ArrayList<Criteria<CodeComment>>();\n\t\t\t\t\t\tfor (var quoted: ctx.criteriaValue.Quoted()) {\n\t\t\t\t\t\t\tString value = getValue(quoted.getText());\n\t\t\t\t\t\t\tif (operator == Mentioned) {\n\t\t\t\t\t\t\t\tcriterias.add(new MentionedUserCriteria(getUser(value)));\n\t\t\t\t\t\t\t} else if (operator == CreatedBy) {\n\t\t\t\t\t\t\t\tcriterias.add(new CreatedByUserCriteria(getUser(value)));\n\t\t\t\t\t\t\t} else if (operator == RepliedBy) {\n\t\t\t\t\t\t\t\tcriterias.add(new RepliedByUserCriteria(getUser(value)));\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tProjectScopedCommit commitId = getCommitId(project, value);\n\t\t\t\t\t\t\t\tcriterias.add(new OnCommitCriteria(commitId.getProject(), commitId.getCommitId()));","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/codecomment/CodeCommentQuery.java#L118-L154","documentation":"The default branch of the switch in visitOperatorCriteria throws ExplicitException \"Unexpected operator: <token>\" when the parser produced an OperatorCriteriaContext whose operator token is not one of Resolved/Unresolved/MentionedMe/CreatedByMe/RepliedByMe. This indicates the lexer matched an operator token that the visitor does not handle, typically after grammar/visitor drift or unusual input.","triggerScenarios":"A query whose bare operator token lexes to a rule not covered by the switch (e.g. an operator keyword that is grammatically valid but not implemented for code comments), or a OneDev version where the grammar and the visitor are out of sync.","commonSituations":"Using operator keywords from another entity's query language (e.g. issue or build query operators) in a code comment query; running a plugin/custom build where grammar and parser code diverge.","solutions":["Check the operator token in the query and replace it with one supported for code comments (Resolved, Unresolved, MentionedMe, CreatedByMe, RepliedByMe, or field-based criteria).","Refer to the code comment query syntax documentation for the installed OneDev version.","Catch ExplicitException around parse() and surface the message to the user.","If it occurs with valid-looking syntax, report/verify against the OneDev version — the visitor may lag the grammar."],"exampleFix":"// before\nvar query = CodeCommentQuery.parse(project, \"State(Tagged)\", true); // operator from issue query language\n// after\nvar query = CodeCommentQuery.parse(project, \"Resolved\", true); // code-comment operator","handlingStrategy":"try-catch","validationCode":"// restrict bare operators to the supported set before parsing\nstatic boolean onlySupportedOperators(String q) {\n    java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"\\\\b([A-Za-z]+)\\\\b\").matcher(q);\n    while (m.find()) {\n        String word = m.group(1);\n        if (word.equals(\"MentionedMe\") || word.equals(\"CreatedByMe\") || word.equals(\"RepliedByMe\")\n                || word.equals(\"Resolved\") || word.equals(\"Unresolved\")\n                || word.equals(\"and\") || word.equals(\"or\") || word.equals(\"not\")\n                || word.equals(\"order\") || word.equals(\"by\") || word.equals(\"asc\") || word.equals(\"desc\"))\n            continue;\n    }\n    return true; // combine with a whitelist of known fields/operators\n}","typeGuard":null,"tryCatchPattern":"try {\n    var query = CodeCommentQuery.parse(project, queryString, true);\n} catch (ExplicitException e) {\n    showUserError(\"Unsupported operator in query: \" + e.getMessage());\n}","preventionTips":["Use only operators documented for code comment queries.","Do not copy operator keywords from issue/build query languages.","Keep grammar and visitor code in sync when customizing OneDev.","Catch ExplicitException at parse time and surface the offending operator."],"tags":["search-query","query-parser","unsupported-operator"],"backgroundTag":"invalid-enum-argument","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"}