{"record":{"id":"ac60f44fecd6a3f6","repo":"theonedev/onedev","slug":"field-not-found-fieldname","errorCode":null,"errorMessage":"Field not found: ${fieldName}","messagePattern":"Field not found: (.+?)","errorType":"validation","errorClass":"ExplicitException","httpStatus":500,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/buildmetric/BuildMetricQuery.java","lineNumber":166,"sourceCode":"\t\t\t\t\tpublic BuildMetricCriteria visitNotCriteria(NotCriteriaContext ctx) {\n\t\t\t\t\t\treturn new NotBuildMetricCriteria(visit(ctx.criteria()));\n\t\t\t\t\t}\n\n\t\t\t\t}.visit(criteriaContext);\n\t\t\t} else {\n\t\t\t\tmetricCriteria = null;\n\t\t\t}\n\n\t\t\treturn new BuildMetricQuery(metricCriteria);\n\t\t} else {\n\t\t\treturn new BuildMetricQuery();\n\t\t}\n\t}\n\t\n\tpublic static void checkField(Project project, String fieldName, int operator) {\n\t\tCollection<String> paramNames = OneDev.getInstance(BuildParamService.class).getParamNames(null);\n\t\tif (!METRIC_QUERY_FIELDS.contains(fieldName) && !paramNames.contains(fieldName)) \n\t\t\tthrow new ExplicitException(\"Field not found: \" + fieldName);\n\t\tswitch (operator) {\n\t\t\tcase Is:\n\t\t\tcase IsNot:\n\t\t\t\tif (!fieldName.equals(NAME_JOB) && !fieldName.equals(NAME_BRANCH)\n\t\t\t\t\t\t&& !fieldName.equals(BuildMetric.NAME_REPORT)\n\t\t\t\t\t\t&& !paramNames.contains(fieldName)) {\n\t\t\t\t\tthrow newOperatorException(fieldName, operator);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase IsEmpty:\n\t\t\tcase IsNotEmpty:\n\t\t\t\tif (!fieldName.equals(NAME_PULL_REQUEST) && !paramNames.contains(fieldName))\n\t\t\t\t\tthrow newOperatorException(fieldName, operator);\n\t\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tprivate static ExplicitException newOperatorException(String fieldName, int operator) {","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/buildmetric/BuildMetricQuery.java#L148-L184","documentation":"BuildMetricQuery.checkField validates that a field name used in a build-metric query criterion is either one of the built-in metric query fields (job name, branch, report, pull request, etc.) or a build parameter name registered with BuildParamService for the project. If the name matches neither list, an ExplicitException with 'Field not found: <fieldName>' is thrown. This guards saved query/criteria definitions against typos and stale field references.","triggerScenarios":"Calling BuildMetricQuery.checkField(project, fieldName, operator) — directly or via visitFieldOperatorCriteria/visitFieldOperatorValueCriteria during query parsing — with a fieldName that is neither in METRIC_QUERY_FIELDS nor in the project's build parameter names (e.g. a typo like 'jobname' instead of 'Job Name', or a parameter that was deleted).","commonSituations":"Typing a wrong field name in a metric query in the UI or REST call; renaming or deleting a build parameter that a saved metric query still references; writing custom code that constructs build metric criteria with an invalid field.","solutions":["Fix the field name to one of the supported metric query fields or an existing build parameter (check the project's build parameter list).","If the field was a build parameter, re-create the parameter in the project's build configuration or update the saved query to drop it.","Catch ExplicitException at the call site to surface a friendly message to the end user instead of a stack trace."],"exampleFix":"// before\nBuildMetricQuery.checkField(project, \"jobname\", operator);\n// after\nBuildMetricQuery.checkField(project, BuildMetricQuery.NAME_JOB, operator);","handlingStrategy":"validation","validationCode":"Set<String> valid = new HashSet<>(BuildMetricQuery.METRIC_QUERY_FIELDS);\nvalid.addAll(OneDev.getInstance(BuildParamService.class).getParamNames(null));\nif (!valid.contains(fieldName)) throw new IllegalArgumentException(\"Unknown field: \" + fieldName);","typeGuard":"boolean isValidMetricField(String f, Project p) {\n    return BuildMetricQuery.METRIC_QUERY_FIELDS.contains(f)\n        || OneDev.getInstance(BuildParamService.class).getParamNames(null).contains(f);\n}","tryCatchPattern":"try {\n    BuildMetricQuery.checkField(project, fieldName, operator);\n} catch (ExplicitException e) {\n    throw new UserFriendlyException(e.getMessage());\n}","preventionTips":["Reference fields via named constants (BuildMetricQuery.NAME_JOB etc.) instead of string literals","Before saving a metric query, re-validate all field names against the current build parameter list","When deleting a build parameter, audit saved queries that reference it"],"tags":["query","validation","build-metrics"],"backgroundTag":"invalid-query-parameter","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"}