bazelbuild/bazel · error · OptionsParsingException

'" + input + "' is not a boolean

Error message

'" + input + "' is not a boolean

What it means

Thrown by Converters.BooleanConverter.convert when the input string (after lowercasing) is not one of the accepted boolean spellings. The converter deliberately accepts several synonyms: true/1/yes/t/y for true and false/0/no/f/n for false, anything else is rejected at option-parsing time with an OptionsParsingException.

Source

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

  private static final ImmutableSet<String> DISABLED_REPS =
      ImmutableSet.of("false", "0", "no", "f", "n");

  /** Standard converter for booleans. Accepts common shorthands/synonyms. */
  public static class BooleanConverter extends Converter.Contextless<Boolean> {
    @Override
    public Boolean convert(String input) throws OptionsParsingException {
      if (input == null) {
        return false;
      }
      input = Ascii.toLowerCase(input);
      if (ENABLED_REPS.contains(input)) {
        return true;
      }
      if (DISABLED_REPS.contains(input)) {
        return false;
      }
      throw new OptionsParsingException("'" + input + "' is not a boolean");
    }

    @Override
    public String getTypeDescription() {
      return "a boolean";
    }
  }

  /** Standard converter for Strings. */
  public static class StringConverter extends Converter.Contextless<String> {
    @Override
    public String convert(String input) {
      return input;
    }

    @Override
    public String getTypeDescription() {
      return "a string";

View on GitHub (pinned to e6e199d060)

Solutions

  1. Use one of the accepted spellings: true/1/yes/t/y or false/0/no/f/n (case-insensitive).
  2. If the value comes from a shell variable, default it: --my_flag=${MY_FLAG:-false}.
  3. Prefer the bare --my_flag / --no_my_flag forms for boolean flags when the parser supports them.

Example fix

# before
bazel build --experimental_new_flag=on //...
# after
bazel build --experimental_new_flag=yes //...
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<String> BOOLS = Set.of(
    "true","1","yes","t","y","false","0","no","f","n");

boolean isParsableBoolean(String s) {
  return s != null && BOOLS.contains(s.toLowerCase(Locale.ROOT));
}

Type guard

boolean isBooleanFlagValue(String s) {
  return s != null && s.matches("(?i)(true|false|1|0|yes|no|t|f|y|n)");
}

Try / catch

try {
  optionsParser.parse(OptionFiltering.ONLY); // or your parse entry point
} catch (OptionsParsingException e) {
  if (e.getMessage().endsWith("is not a boolean")) { /* tell user accepted spellings */ }
}

Prevention

When it happens

Trigger: Passing a flag value such as --my_flag=on, --my_flag=enabled, --my_flag="" or --my_flag=truee to any option whose converter is BooleanConverter (the default for boolean flags using this converter).

Common situations: Copy-pasting config from other tools that accept on/off or enabled/disabled; empty variable expansion producing --my_flag=; quoting mistakes that leave trailing whitespace or a stray character on the value.

Related errors


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