theonedev/onedev · error · ExplicitException
Unexpected operator:
Error message
Unexpected operator:
What it means
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.
Source
Thrown at server-core/src/main/java/io/onedev/server/search/entity/codecomment/CodeCommentQuery.java:136
switch (ctx.operator.getType()) {
case Resolved:
return new ResolvedCriteria();
case Unresolved:
return new UnresolvedCriteria();
case MentionedMe:
if (!withCurrentUserCriteria)
throw new ExplicitException("Criteria '" + ctx.operator.getText() + "' is not supported here");
return new MentionedMeCriteria();
case CreatedByMe:
if (!withCurrentUserCriteria)
throw new ExplicitException("Criteria '" + ctx.operator.getText() + "' is not supported here");
return new CreatedByMeCriteria();
case RepliedByMe:
if (!withCurrentUserCriteria)
throw new ExplicitException("Criteria '" + ctx.operator.getText() + "' is not supported here");
return new RepliedByMeCriteria();
default:
throw new ExplicitException("Unexpected operator: " + ctx.operator.getText());
}
}
@Override
public Criteria<CodeComment> visitOperatorValueCriteria(OperatorValueCriteriaContext ctx) {
int operator = ctx.operator.getType();
var criterias = new ArrayList<Criteria<CodeComment>>();
for (var quoted: ctx.criteriaValue.Quoted()) {
String value = getValue(quoted.getText());
if (operator == Mentioned) {
criterias.add(new MentionedUserCriteria(getUser(value)));
} else if (operator == CreatedBy) {
criterias.add(new CreatedByUserCriteria(getUser(value)));
} else if (operator == RepliedBy) {
criterias.add(new RepliedByUserCriteria(getUser(value)));
} else {
ProjectScopedCommit commitId = getCommitId(project, value);
criterias.add(new OnCommitCriteria(commitId.getProject(), commitId.getCommitId()));View on GitHub (pinned to d44925c47c)
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.
Example fix
// before var query = CodeCommentQuery.parse(project, "State(Tagged)", true); // operator from issue query language // after var query = CodeCommentQuery.parse(project, "Resolved", true); // code-comment operator
Defensive patterns
Strategy: try-catch
Validate before calling
// restrict bare operators to the supported set before parsing
static boolean onlySupportedOperators(String q) {
java.util.regex.Matcher m = java.util.regex.Pattern.compile("\\b([A-Za-z]+)\\b").matcher(q);
while (m.find()) {
String word = m.group(1);
if (word.equals("MentionedMe") || word.equals("CreatedByMe") || word.equals("RepliedByMe")
|| word.equals("Resolved") || word.equals("Unresolved")
|| word.equals("and") || word.equals("or") || word.equals("not")
|| word.equals("order") || word.equals("by") || word.equals("asc") || word.equals("desc"))
continue;
}
return true; // combine with a whitelist of known fields/operators
} Try / catch
try {
var query = CodeCommentQuery.parse(project, queryString, true);
} catch (ExplicitException e) {
showUserError("Unsupported operator in query: " + e.getMessage());
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "invalid argument", "unknown mode", "not supported": invalid enum-like argument errors explained — this error's family across 19 libraries.
Related errors
- Malformed query
- Criteria '' is not supported here
- Cannot order by field:
- Field not found:
- Unexpected operator: " + ctx.operator.getText()
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/69e86cc4449e8704.
Report an issue: GitHub.