theonedev/onedev · error · ValidationException

Invalid choice values:

Error message

Invalid choice values: 

What it means

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.

Source

Thrown at server-core/src/main/java/io/onedev/server/buildspecmodel/inputspec/choiceinput/ChoiceInput.java:57

		}
		inputSpec.appendChoiceProvider(buffer, index, "@ChoiceProvider");
		
		if (inputSpec.isAllowMultiple())
			inputSpec.appendMethods(buffer, index, "List<String>", choiceProvider, defaultMultiValueProvider);
		else 
			inputSpec.appendMethods(buffer, index, "String", choiceProvider, defaultValueProvider);
		
		return buffer.toString();
	}

	public static Object convertToObject(InputSpec inputSpec, List<String> strings) {
		if (inputSpec.isAllowMultiple()) {
			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;
			}

View on GitHub (pinned to d44925c47c)

Solutions

  1. 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).
  2. If new values are legitimate, add them to the input's possibleValues list in the build spec.
  3. If possibleValues is empty, the check is skipped — remove/relocate values or clear possibleValues if free-form input is intended.
  4. Verify dynamic choice providers (ScriptingChoices) return values consistent with any static possibleValues.

Example fix

// before (job spec)
inputs:
  environment:
    type: choice
    allowMultiple: true
    possibleValues: [dev, staging]
    value: [dev, prod]   // prod not declared
// after
    value: [dev, staging]
Defensive patterns

Strategy: validation

Validate before calling

List<String> invalid = new ArrayList<>(values);
invalid.removeAll(inputSpec.getPossibleValues());
if (inputSpec.isAllowMultiple() && !inputSpec.getPossibleValues().isEmpty() && !invalid.isEmpty())
    throw new IllegalArgumentException("Values not in choice list: " + invalid);

Type guard

boolean allAllowed(List<String> values, ChoiceInput spec) {
    return !spec.isAllowMultiple() || spec.getPossibleValues().isEmpty()
        || spec.getPossibleValues().containsAll(values);
}

Try / catch

try {
    Object result = ChoiceInput.convertToObject(inputSpec, strings);
} catch (ValidationException e) {
    logger.warn("Invalid choice values submitted: {}", strings);
    // surface e.getMessage() to user / fall back to defaults
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

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


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/ef0f45155f55321b. Report an issue: GitHub.