{"record":{"id":"ef0f45155f55321b","repo":"theonedev/onedev","slug":"invalid-choice-values","errorCode":null,"errorMessage":"Invalid choice values: ","messagePattern":"Invalid choice values: ","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/choiceinput/ChoiceInput.java","lineNumber":57,"sourceCode":"\t\t}\n\t\tinputSpec.appendChoiceProvider(buffer, index, \"@ChoiceProvider\");\n\t\t\n\t\tif (inputSpec.isAllowMultiple())\n\t\t\tinputSpec.appendMethods(buffer, index, \"List<String>\", choiceProvider, defaultMultiValueProvider);\n\t\telse \n\t\t\tinputSpec.appendMethods(buffer, index, \"String\", choiceProvider, defaultValueProvider);\n\t\t\n\t\treturn buffer.toString();\n\t}\n\n\tpublic static Object convertToObject(InputSpec inputSpec, List<String> strings) {\n\t\tif (inputSpec.isAllowMultiple()) {\n\t\t\tList<String> possibleValues = inputSpec.getPossibleValues();\n\t\t\tif (!possibleValues.isEmpty()) {\n\t\t\t\tList<String> copyOfStrings = new ArrayList<>(strings);\n\t\t\t\tcopyOfStrings.removeAll(possibleValues);\n\t\t\t\tif (!copyOfStrings.isEmpty())\n\t\t\t\t\tthrow new ValidationException(\"Invalid choice values: \" + copyOfStrings);\n\t\t\t\telse\n\t\t\t\t\treturn strings;\n\t\t\t} else {\n\t\t\t\treturn strings;\n\t\t\t}\n\t\t} else if (strings.size() == 0) {\n\t\t\treturn null;\n\t\t} else if (strings.size() == 1) {\n\t\t\tString value = strings.iterator().next();\n\t\t\tList<String> possibleValues = inputSpec.getPossibleValues();\n\t\t\tif (!possibleValues.isEmpty()) {\n\t\t\t\tif (!possibleValues.contains(value))\n\t\t\t\t\tthrow new ValidationException(\"Invalid choice value\");\n\t\t\t\telse\n\t\t\t\t\treturn value;\n\t\t\t} else {\n\t\t\t\treturn value;\n\t\t\t}","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/choiceinput/ChoiceInput.java#L39-L75","documentation":"ChoiceInput.convertToObject validates user-supplied choice input values against the input spec's declared possibleValues when allowMultiple is true. Any submitted strings not present in the allowed list are collected and thrown as a ValidationException listing the offending values. This guards build spec inputs from accepting values outside the configured choice set.","triggerScenarios":"Calling ChoiceInput.convertToObject on a ChoiceInput with isAllowMultiple()==true and a non-empty possibleValues list, where the submitted string collection contains at least one value not in possibleValues (copyOfStrings.removeAll(possibleValues) leaves entries).","commonSituations":"Build spec .yml references a choice value that was renamed or removed from the input's possible values; a job param script generates values that drift from the declared choice list; typo'd or case-mismatched choice values in job parameters or pom/job spec files.","solutions":["Check the error message for the listed invalid values and correct them to exactly match one of the input's declared possible values (case-sensitive).","If new values are legitimate, add them to the input's possibleValues list in the build spec.","If possibleValues is empty, the check is skipped — remove/relocate values or clear possibleValues if free-form input is intended.","Verify dynamic choice providers (ScriptingChoices) return values consistent with any static possibleValues."],"exampleFix":"// before (job spec)\ninputs:\n  environment:\n    type: choice\n    allowMultiple: true\n    possibleValues: [dev, staging]\n    value: [dev, prod]   // prod not declared\n// after\n    value: [dev, staging]","handlingStrategy":"validation","validationCode":"List<String> invalid = new ArrayList<>(values);\ninvalid.removeAll(inputSpec.getPossibleValues());\nif (inputSpec.isAllowMultiple() && !inputSpec.getPossibleValues().isEmpty() && !invalid.isEmpty())\n    throw new IllegalArgumentException(\"Values not in choice list: \" + invalid);","typeGuard":"boolean allAllowed(List<String> values, ChoiceInput spec) {\n    return !spec.isAllowMultiple() || spec.getPossibleValues().isEmpty()\n        || spec.getPossibleValues().containsAll(values);\n}","tryCatchPattern":"try {\n    Object result = ChoiceInput.convertToObject(inputSpec, strings);\n} catch (ValidationException e) {\n    logger.warn(\"Invalid choice values submitted: {}\", strings);\n    // surface e.getMessage() to user / fall back to defaults\n}","preventionTips":["Keep a single source of truth for possibleValues and generate consumer values from it.","Validate build spec values in CI before deploying the spec.","Watch for renames of choice options; migrate stored job parameters when renaming.","Remember matching is exact and case-sensitive."],"tags":["validation","buildspec","choice-input"],"backgroundTag":"invalid-enum-value","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"}