{"record":{"id":"f2a8228952e7b1fc","repo":"bazelbuild/bazel","slug":"setvalue-operation-from-invocation-policy-for-has","errorCode":null,"errorMessage":"SetValue operation from invocation policy for has an undefined behavior: %s","messagePattern":"SetValue operation from invocation policy for has an undefined behavior: (.+?)","errorType":"exception","errorClass":"OptionsParsingException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java","lineNumber":313,"sourceCode":"\n    return effectivePolicy.buildKeepingLast().values().asList();\n  }\n\n  private static void throwAllowValuesOnExpansionFlagException(String flagName)\n      throws OptionsParsingException {\n    throw new OptionsParsingException(\n        String.format(\"Allow_Values on expansion flags like %s is not allowed.\", flagName));\n  }\n\n  private static void throwDisallowValuesOnExpansionFlagException(String flagName)\n      throws OptionsParsingException {\n    throw new OptionsParsingException(\n        String.format(\"Disallow_Values on expansion flags like %s is not allowed.\", flagName));\n  }\n\n  private static OptionsParsingException throwUndefinedBehaviorException(FlagPolicy policy)\n      throws OptionsParsingException {\n    throw new OptionsParsingException(\n        String.format(\n            \"SetValue operation from invocation policy for has an undefined behavior: %s\",\n            policy\n            ));\n  }\n\n  /**\n   * Expand a single policy. If the policy is not about an expansion flag, this will simply return a\n   * list with a single element, oneself. If the policy is for an expansion flag, the policy will\n   * get split into multiple policies applying to each flag the original flag expands to.\n   *\n   * <p>None of the flagPolicies returned should be on expansion flags.\n   */\n  private static ImmutableList<FlagPolicyWithContext> expandPolicy(\n      FlagPolicyWithContext originalPolicy, OptionsParser parser, Level loglevel)\n      throws OptionsParsingException {\n    ImmutableList.Builder<FlagPolicyWithContext> expandedPolicies = ImmutableList.builder();\n","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java#L295-L331","documentation":"Thrown by throwUndefinedBehaviorException when a policy's set_value operation has behavior = UNDEFINED (the proto default), which deliberately means 'behavior was not specified'. Because the enforcement semantics (override vs final vs append) are ambiguous, the enforcer refuses rather than guessing. The message text itself contains a grammar slip ('for has an undefined behavior').","triggerScenarios":"A policy entry with setValue present (and flagValue list non-empty) but behavior omitted, e.g. {\"flagName\":\"...\",\"setValue\":{\"flagValue\":[\"x\"]}} — in proto3 JSON, omitting behavior leaves it at the UNDEFINED enum default.","commonSituations":"Hand-written policy JSON that only sets flagValue, samples copied from docs that omit the behavior field, protobuf field-name typos (behavior vs behaviour), policy generators that skip defaulted fields.","solutions":["Add an explicit behavior to the setValue operation: ALLOW_OVERRIDES, FINAL_VALUE_IGNORE_OVERRIDES, FINAL_VALUE_THROW_ON_OVERRIDE, or APPEND.","Prefer FINAL_VALUE_IGNORE_OVERRIDES or FINAL_VALUE_THROW_ON_OVERRIDE for org-enforced settings; ALLOW_OVERRIDES when users may override.","Lint policy files programmatically: assert setValue.behavior != UNDEFINED for every entry before rollout."],"exampleFix":"// before\n{\"flagName\":\"compilation_mode\",\"setValue\":{\"flagValue\":[\"opt\"]}}\n\n// after\n{\"flagName\":\"compilation_mode\",\"setValue\":{\"flagValue\":[\"opt\"],\"behavior\":\"FINAL_VALUE_IGNORE_OVERRIDES\"}}","handlingStrategy":"validation","validationCode":"// Assert every setValue entry has an explicit behavior\nfor (FlagPolicy fp : policy.getFlagPoliciesList()) {\n  if (fp.hasSetValue() && fp.getSetValue().getBehavior() == SetValue.Behavior.UNDEFINED) {\n    throw new IllegalStateException(\"setValue for '\" + fp.getFlagName() + \"' needs an explicit behavior\");\n  }\n}","typeGuard":null,"tryCatchPattern":"Catch OptionsParsingException; treat as a policy file defect — add an explicit behavior enum value and redeploy the policy.","preventionTips":["Never omit behavior in setValue entries; proto3 defaults make it UNDEFINED","Template policies with behavior as a required template variable","Remember FINAL_VALUE_IGNORE_OVERRIDES vs THROW_ON_OVERRIDE semantics when choosing"],"tags":["invocation-policy","set-value","protobuf-defaults","bazel"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}