theonedev/onedev · error · ValidationException
Invalid choice value
Error message
Invalid choice value
What it means
ChoiceInput.convertToObject validates a single-choice input value. When the input is not multi-value and exactly one string is submitted, the value must exist in the input's possibleValues list; otherwise a ValidationException is thrown. The message does not echo the offending value, so consult the spec to find what is allowed.
Source
Thrown at server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/choiceinput/ChoiceInput.java:70
List<String> possibleValues = inputSpec.getPossibleValues();
if (!possibleValues.isEmpty()) {
List<String> copyOfStrings = new ArrayList<>(strings);
copyOfStrings.removeAll(possibleValues);
if (!copyOfStrings.isEmpty())
throw new ValidationException("Invalid choice values: " + copyOfStrings);
else
return strings;
} else {
return strings;
}
} else if (strings.size() == 0) {
return null;
} else if (strings.size() == 1) {
String value = strings.iterator().next();
List<String> possibleValues = inputSpec.getPossibleValues();
if (!possibleValues.isEmpty()) {
if (!possibleValues.contains(value))
throw new ValidationException("Invalid choice value");
else
return value;
} else {
return value;
}
} else {
throw new ValidationException("Not eligible for multi-value");
}
}
@SuppressWarnings("unchecked")
public static List<String> convertToStrings(InputSpec inputSpec, Object value) {
List<String> strings = new ArrayList<>();
if (inputSpec.isAllowMultiple()) {
if (inputSpec.checkListElements(value, String.class))
strings.addAll((List<String>) value);
Collections.sort(strings);
} else if (value instanceof String) {View on GitHub (pinned to d44925c47c)
Solutions
- Compare the submitted value against the input's possibleValues and fix the spelling/case to match exactly.
- Update stale job parameters or schedules still referencing a renamed choice value.
- Add the value to possibleValues if it is a legitimate new option.
- If free-form values are desired, clear possibleValues (empty list bypasses the check).
Example fix
// before value: "Prod" // possibleValues: [prod, staging] // after value: "prod"
Defensive patterns
Strategy: validation
Validate before calling
if (values.size() == 1 && !inputSpec.getPossibleValues().isEmpty()
&& !inputSpec.getPossibleValues().contains(values.iterator().next()))
throw new IllegalArgumentException("Value not in choice list: " + values.iterator().next()); Type guard
boolean isAllowedChoice(String value, ChoiceInput spec) {
return spec.getPossibleValues().isEmpty() || spec.getPossibleValues().contains(value);
} Try / catch
try {
Object result = ChoiceInput.convertToObject(inputSpec, strings);
} catch (ValidationException e) {
logger.warn("Value {} is not one of {}", strings, inputSpec.getPossibleValues());
// prompt user to re-pick or use a default
} Prevention
- Populate choice inputs from a dropdown fed by possibleValues rather than free text.
- Use the ChoiceInput's own UI component so only valid values can be submitted.
- Migrate persisted parameters whenever possibleValues change.
- Check case-sensitivity when copying values.
When it happens
Trigger: Calling ChoiceInput.convertToObject on a ChoiceInput with isAllowMultiple()==false, exactly one submitted string, and a non-empty possibleValues list that does not contain that string (possibleValues.contains(value) is false).
Common situations: Typo or case mismatch in a job parameter value; the choice list was renamed in the build spec while old values persist in saved job pipelines or schedules; copy-pasting a value from a different input.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Invalid choice values:
- Circular template usages (
- Error validating step template parameters (%s)
- Step template not found (
- Circular dependencies (
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/68fd0ac3ee32238f.
Report an issue: GitHub.