{"record":{"id":"ef15c7f2bdc47458","repo":"theonedev/onedev","slug":"no-commit-in-query-context-ef15c7","errorCode":null,"errorMessage":"No commit in query context","messagePattern":"No commit in query context","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/issue/FixedInCurrentCommitCriteria.java","lineNumber":32,"sourceCode":"\npublic class FixedInCurrentCommitCriteria extends Criteria<Issue> {\n\n\tprivate static final long serialVersionUID = 1L;\n\t\n\t@Override\n\tpublic Predicate getPredicate(@Nullable ProjectScope projectScope, CriteriaQuery<?> query, From<Issue, Issue> from, CriteriaBuilder builder) {\n\t\tif (ProjectScopedCommit.get() != null)\n\t\t\treturn new FixedInCommitCriteria(ProjectScopedCommit.get()).getPredicate(projectScope, query, from, builder);\n\t\telse\n\t\t\tthrow new ExplicitException(\"No commit id in query context\");\n\t}\n\n\t@Override\n\tpublic boolean matches(Issue issue) {\n\t\tif (ProjectScopedCommit.get() != null)\n\t\t\treturn new FixedInCommitCriteria(ProjectScopedCommit.get()).matches(issue);\n\t\telse\n\t\t\tthrow new ExplicitException(\"No commit in query context\");\n\t}\n\n\t@Override\n\tpublic String toStringWithoutParens() {\n\t\treturn IssueQuery.getRuleName(IssueQueryLexer.FixedInCurrentCommit);\n\t}\n\n}\n","sourceCodeStart":14,"sourceCodeEnd":41,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/FixedInCurrentCommitCriteria.java#L14-L41","documentation":"FixedInCurrentCommitCriteria.matches() throws this ExplicitException when the in-memory matching path is used for the '~Fixed in current commit' rule without a commit in the query context. Like getPredicate(), it depends on ProjectScopedCommit.get() to know which commit to delegate to; with a null context it cannot decide whether the issue is fixed in the commit.","triggerScenarios":"Calling matches(issue) on a query or criterion containing FixedInCurrentCommit when ProjectScopedCommit.get() is null.","commonSituations":"In-memory issue filtering (e.g. client-side or service-side matches() evaluation) outside of a commit page or commit-triggered job; running saved queries in webhooks or scripts lacking commit context.","solutions":["Run the matching only within a commit context, or set ProjectScopedCommit before calling matches().","Replace the current-commit rule with an explicit '~Fixed in commit(<hash>)' criterion in saved queries.","Filter queries containing context-relative rules out before in-memory evaluation, or pre-validate with ProjectScopedCommit.get() != null.","Catch ExplicitException and fall back to a fixed context or skip the criterion with a warning."],"exampleFix":"// before\ncriteria.matches(issue); // ProjectScopedCommit.get() == null\n// after\nif (ProjectScopedCommit.get() != null) {\n    criteria.matches(issue);\n} else {\n    throw new ExplicitException(\"Evaluate this query within a commit context\");\n}","handlingStrategy":"try-catch","validationCode":"if (ProjectScopedCommit.get() == null) {\n    return; // skip in-memory evaluation; no commit context\n}","typeGuard":"boolean canEvaluateFixedInCurrentCommit() {\n    return ProjectScopedCommit.get() != null;\n}","tryCatchPattern":"try {\n    boolean hit = criteria.matches(issue);\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"No commit in query context\")) {\n        // handle missing commit context (skip, log, or re-run with context)\n    } else {\n        throw e;\n    }\n}","preventionTips":["Guard matches() calls with a null-check of ProjectScopedCommit.get()","Avoid reusing commit-scoped queries in services/scripts without setting context","Use explicit commit criteria in stored queries","Surface the ExplicitException message to users instead of swallowing it"],"tags":["onedev","issue-query","query-context","commit"],"backgroundTag":"missing-query-context","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}