bazelbuild/bazel · error · OptionsParsingException

Empty values are not allowed as part of this " + getTypeDesc

Error message

Empty values are not allowed as part of this " + getTypeDescription()

What it means

Thrown by the list converter in Converters (line 303) when the split of a comma/space-separated option value yields an empty element in a multi-element list and the converter was built with allowEmptyValues=false. A value that is exactly one empty string is tolerated (treated as the empty list), but embedded empties like "a,,b" are rejected.

Source

Thrown at src/main/java/com/google/devtools/common/options/Converters.java:303

    protected SeparatedOptionListConverter(
        char separator, String separatorDescription, boolean allowEmptyValues) {
      this.separatorDescription = separatorDescription;
      this.splitter = Splitter.on(separator);
      this.allowEmptyValues = allowEmptyValues;
    }

    @Override
    public ImmutableList<String> convert(String input) throws OptionsParsingException {
      ImmutableList<String> result =
          input.isEmpty() ? ImmutableList.of() : ImmutableList.copyOf(splitter.split(input));
      if (!allowEmptyValues && result.contains("")) {
        // If the list contains exactly the empty string, it means an empty value was passed and we
        // should instead return an empty list.
        if (result.size() == 1) {
          return ImmutableList.of();
        }

        throw new OptionsParsingException(
            "Empty values are not allowed as part of this " + getTypeDescription());
      }
      return result;
    }

    @Override
    public String getTypeDescription() {
      return separatorDescription + "-separated list of options";
    }
  }

  /**
   * Converter for options separated by some separator character, where order and count do not
   * matter, i.e. semantically it is a set, not a list.
   */
  public static class SeparatedOptionSetConverter extends SeparatedOptionListConverter {
    private final String separatorDescription;

View on GitHub (pinned to e6e199d060)

Solutions

  1. Remove empty segments from the value: --my_list=a,b.
  2. Sanitize before passing: strip leading/trailing separators and collapse doubled ones.
  3. If empty entries are meaningful, use or request a converter constructed with allowEmptyValues=true.

Example fix

# before
bazel build --my_list=$A,$B   # A unset -> ",b"
# after
LIST=$(printf '%s\n' "$A" "$B" | grep -v '^$' | paste -sd, -)
bazel build --my_list=$LIST
Defensive patterns

Strategy: validation

Validate before calling

boolean hasNoEmptySegments(String listValue, char sep) {
  if (listValue.isEmpty()) return true; // single empty is tolerated
  for (String part : listValue.split(Pattern.quote(String.valueOf(sep)), -1)) {
    if (part.isEmpty()) return false;
  }
  return true;
}

Type guard

boolean isCleanListValue(String v) {
  return v != null && !v.startsWith(",") && !v.endsWith(",") && !v.contains(",,");
}

Prevention

When it happens

Trigger: Passing --my_list=a,,b or --my_list=,x (leading/trailing separator producing an empty first/last element in a list of size > 1) to an option using this converter with empty values disallowed.

Common situations: Comma-joined shell variables where one element is empty (JOIN="$A,$B" with A unset); trailing separators left by scripts; cleanup logic that produces consecutive separators.

Related errors


AI-assisted analysis of bazelbuild/bazel@e6e199d060 (2026-08-14). Data as JSON: /api/errors/ace7245c68f2e739. Report an issue: GitHub.