{"record":{"id":"4cb7b2cc80d982dc","repo":"theonedev/onedev","slug":"no-build-in-query-context","errorCode":null,"errorMessage":"No build in query context","messagePattern":"No build in query context","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/entity/issue/FieldOperatorCriteria.java","lineNumber":143,"sourceCode":"\t\t\telse\n\t\t\t\treturn fieldValue == null;\n\t\t} else if (operator == IssueQueryLexer.IsMe) {\n\t\t\tif (User.get() != null) {\n\t\t\t\tvar userName = User.get().getName();\n\t\t\t\tif (fieldValue instanceof Collection)\n\t\t\t\t\treturn ((Collection) fieldValue).contains(userName);\n\t\t\t\telse \n\t\t\t\t\treturn Objects.equals(fieldValue, userName);\n\t\t\t} else {\n\t\t\t\tthrow new NotAcceptableException(_T(\"Please login to perform this query\"));\n\t\t\t}\n\t\t} else if (operator == IssueQueryLexer.IsCurrent) {\n\t\t\tif (getFieldSpec() instanceof BuildChoiceField) {\n\t\t\t\tBuild build = Build.get();\n\t\t\t\tif (build != null) \n\t\t\t\t\treturn build.getProject().equals(issue.getProject()) && build.getId().toString().equals(fieldValue);\n\t\t\t\telse  \n\t\t\t\t\tthrow new ExplicitException(_T(\"No build in query context\"));\n\t\t\t} else if (getFieldSpec() instanceof PullRequestChoiceField) {\n\t\t\t\tPullRequest request = PullRequest.get();\n\t\t\t\tif (request != null) \n\t\t\t\t\treturn request.getTargetProject().equals(issue.getProject()) && request.getId().toString().equals(fieldValue);\n\t\t\t\telse  \n\t\t\t\t\tthrow new ExplicitException(_T(\"No pull request in query context\"));\n\t\t\t} else if (getFieldSpec() instanceof CommitField) {\n\t\t\t\tProjectScopedCommit commit = ProjectScopedCommit.get();\n\t\t\t\tif (commit != null) \n\t\t\t\t\treturn commit.getProject().equals(issue.getProject()) && commit.getCommitId().name().equals(fieldValue);\n\t\t\t\telse  \n\t\t\t\t\tthrow new ExplicitException(_T(\"No commit in query context\"));\n\t\t\t} else {\n\t\t\t\tthrow new IllegalStateException();\n\t\t\t}\n\t\t} else if (operator == IssueQueryLexer.IsPrevious) {\n\t\t\tif (getFieldSpec() instanceof BuildChoiceField) {\n\t\t\t\tBuild build = Build.get();","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/entity/issue/FieldOperatorCriteria.java#L125-L161","documentation":"When an issue criteria uses a BuildChoiceField with the 'is current' operator, the in-memory matches() evaluation reads Build.get() from the query context. If no build is bound, an ExplicitException is thrown because the criteria cannot compare against a current build.","triggerScenarios":"Evaluating a query with a BuildChoiceField 'is current build' criteria via matches() while no Build is set in the context — e.g. the global issue list, REST queries, or background processing without build context.","commonSituations":"Saved filters from a build page reused on the project issue list; scripts evaluating issue rules outside CI; queries embedded in reports executed server-side.","solutions":["Execute the query in a build-bound context (build issue list or code that sets Build)","Substitute an explicit build number/id in the query instead of 'is current build'","Catch ExplicitException and skip or rewrite the criteria when context is absent","Ensure CI integrations bind the current Build before running issue queries"],"exampleFix":"// before\nIssueQuery query = IssueQuery.parse(\"\\\"Build\\\" is current build\");\nissueManager.query(project, query); // throws without build\n// after\nBuild build = Build.get();\nIssueQuery query = IssueQuery.parse(build!=null ? \"\\\"Build\\\" is current build\" : \"\\\"Build\\\" is \"+buildNumber);","handlingStrategy":"try-catch","validationCode":"if (Build.get() == null) { throw new IllegalStateException(\"'is current build' criteria requires build context\"); }","typeGuard":"boolean hasBuildContext() { return Build.get() != null; }","tryCatchPattern":"try { result = issues.stream().filter(query::matches).collect(toList()); } catch (ExplicitException e) { if (e.getMessage().contains(\"build\")) { result = List.of(); } else { throw e; } }","preventionTips":["Check Build.get() before in-memory matching of build criteria","Use explicit build ids in non-CI contexts","Bind Build before programmatic query evaluation","Keep build-dependent filters out of globally reused saved queries"],"tags":["onedev","issue-query","build","query-context"],"backgroundTag":"missing-required-config","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"}