{"record":{"id":"57f3a270f7ffee68","repo":"bazelbuild/bazel","slug":"svalues-policy-disallows-the-default-value-s-f","errorCode":null,"errorMessage":"%sValues policy disallows the default value '%s' for %s but also specifies to use the default value","messagePattern":"(.+?)Values policy disallows the default value '(.+?)' for (.+?) but also specifies to use the default value","errorType":"exception","errorClass":"OptionsParsingException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java","lineNumber":754,"sourceCode":"        }\n      }\n\n      // Check that if the default value of the flag is disallowed by the policy, that the policy\n      // does not also set use_default. Otherwise the default value would still be set if the\n      // user uses a disallowed value. This doesn't apply to repeatable flags since the default\n      // value for repeatable flags is always the empty list. It also doesn't apply to flags that\n      // are null by default, since these flags' default value is not parsed by the converter, so\n      // there is no guarantee that there exists an accepted user-input value that would also set\n      // the value to NULL. In these cases, we assume that \"unset\" is a distinct value that is\n      // always allowed.\n      if (!optionDescription.getOptionDefinition().allowsMultiple()\n          && !optionDescription.getOptionDefinition().isSpecialNullDefault()) {\n        boolean defaultValueAllowed =\n            isFlagValueAllowed(\n                convertedPolicyValues,\n                optionDescription.getOptionDefinition().getDefaultValue(conversionContext));\n        if (!defaultValueAllowed && useDefault) {\n          throw new OptionsParsingException(\n              String.format(\n                  \"%sValues policy disallows the default value '%s' for %s but also specifies to \"\n                      + \"use the default value\",\n                  policyType,\n                  optionDefinition.getDefaultValue(conversionContext),\n                  optionDefinition));\n        }\n      }\n\n      if (valueDescription == null) {\n        // Nothing has set the value yet, so check that the default value from the flag's\n        // definition is allowed. The else case below (i.e. valueDescription is not null) checks for\n        // the flag allowing multiple values, however, flags that allow multiple values cannot have\n        // default values, and their value is always the empty list if they haven't been specified,\n        // which is why new_default_value is not a repeated field.\n        checkDefaultValue(\n            parser,\n            origin,","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java#L736-L772","documentation":"Thrown in the values-checking path (checkDefaultValue) when an allow_values/disallow_values policy both disallows the flag's default value and sets use_default — a contradictory policy (use the default that you forbid). Skipped for repeatable flags (default is always empty list) and special-null-default flags, where 'unset' is treated as always allowed.","triggerScenarios":"Policy on a single-valued flag with a non-null default: disallowValues lists the default value (without newValue) plus useDefault=true; or allowValues omits the default plus useDefault=true. E.g. flag default 'fastbuild', policy allows only ['opt'] and says use default — contradiction.","commonSituations":"Policy authors restricting a flag to a value while reflexively adding use_default as a 'safe fallback', porting policies between flags with different defaults without re-checking the default value, generated policies that always set both fields.","solutions":["Remove use_default from the policy entry, or extend the allowed set / shrink the disallowed set so the flag's default is permitted.","Supply a newValue in disallow_values so the default is replaced rather than 'used'.","Check the flag's default (bazel help) whenever writing allow/disallow policies against it."],"exampleFix":"// before (default is fastbuild)\n{\"flagName\":\"compilation_mode\",\"allowValues\":{\"allowedValues\":[\"opt\"]},\"useDefault\":true}\n\n// after\n{\"flagName\":\"compilation_mode\",\"allowValues\":{\"allowedValues\":[\"opt\"]}}","handlingStrategy":"validation","validationCode":"// Lint: use_default together with a default-disallowing allow/disallow set is contradictory\nObject def = optionDefinition.getDefaultValue(ctx);\nif (usesUseDefault(fp) && !isValueAllowedByPolicy(fp, def)) {\n  throw new IllegalStateException(\"Policy forbids the default but also sets use_default\");\n}","typeGuard":null,"tryCatchPattern":"Catch OptionsParsingException at policy enforcement; resolve the contradiction by removing use_default or allowing the default value.","preventionTips":["Never pair use_default with a value set that excludes the flag's default","Look up each flag's default in bazel help before writing allow/disallow policies","Provide newValue instead of use_default when replacing a disallowed default"],"tags":["invocation-policy","default-values","contradictory-policy","bazel"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}