{"record":{"id":"8f21f503c3fd6fef","repo":"bazelbuild/bazel","slug":"can-t-set-an-option-to-accumulate-multiple-values","errorCode":null,"errorMessage":"Can't set an option to accumulate multiple values and let it expand to other flags.","messagePattern":"Can't set an option to accumulate multiple values and let it expand to other flags\\.","errorType":"validation","errorClass":"OptionProcessorException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/processor/OptionsClassProcessor.java","lineNumber":445,"sourceCode":"              + annotation.category()\n              + \"\\\" is disallowed, see OptionMetadataTags for the relevant tags.\");\n    }\n  }\n\n  private void checkExpansionOptions(ExecutableElement method) throws OptionProcessorException {\n    Option annotation = method.getAnnotation(Option.class);\n    boolean isExpansion = annotation.expansion().length > 0;\n    boolean hasImplicitRequirements = annotation.implicitRequirements().length > 0;\n\n    if (isExpansion && hasImplicitRequirements) {\n      throw new OptionProcessorException(\n          method,\n          \"Can't set an option to be both an expansion option and have implicit requirements.\");\n    }\n\n    if (isExpansion || hasImplicitRequirements) {\n      if (annotation.allowMultiple()) {\n        throw new OptionProcessorException(\n            method,\n            \"Can't set an option to accumulate multiple values and let it expand to other flags.\");\n      }\n    }\n  }\n\n  private void checkNoDefaultValueForMultipleOption(ExecutableElement method)\n      throws OptionProcessorException {\n    Option annotation = method.getAnnotation(Option.class);\n    if (annotation.allowMultiple()\n        && !annotation.defaultValue().equals(\"null\")\n        && !ImmutableList.of(\"runs_per_test\", \"flaky_test_attempts\").contains(annotation.name())) {\n      throw new OptionProcessorException(\n          method,\n          \"Default values for multiple options are not allowed - use \\\"null\\\" special value\");\n    }\n  }\n","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/processor/OptionsClassProcessor.java#L427-L463","documentation":"This compile-time error from Bazel's options annotation processor fires when an option with allowMultiple = true is also an expansion option or has implicit requirements. Repeated (accumulating) options cannot also rewrite the command line, because each occurrence would expand or add requirements in ways the parser cannot accumulate coherently.","triggerScenarios":"An @Option with allowMultiple = true where expansion.length > 0 or implicitRequirements.length > 0.","commonSituations":"Taking a single-value expansion flag and switching it to allowMultiple so users can pass it repeatedly; adding expansion to an existing list-type option to alias several flags; converting a comma-separated option into a repeatable one without removing its expansion.","solutions":["Decide the option's role: for expansion/implicit-requirement flags, remove allowMultiple (they should be Void-typed single-occurrence options).","For repeatable value-collection options, remove the expansion and implicitRequirements attributes and let each --flag=value occurrence append to the List.","If you need both behaviors, split into two options: one repeatable plain option and one expansion option referencing it.","Recompile to verify."],"exampleFix":"// before\n@Option(\n  name = \"multi_expand\",\n  defaultValue = \"null\",\n  allowMultiple = true,\n  expansion = {\"--foo\", \"--bar\"}\n)\n// after (repeatable plain option; expansion handled by a separate Void option)\n@Option(\n  name = \"multi_expand\",\n  defaultValue = \"null\",\n  allowMultiple = true,\n  documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,\n  effectTags = {OptionEffectTag.EAGER}\n)","handlingStrategy":"validation","validationCode":"static void checkMultipleNotExpanding(boolean allowMultiple,\n                                      String[] expansion,\n                                      String[] implicitRequirements) {\n  if (allowMultiple) {\n    Preconditions.checkState(expansion.length == 0 && implicitRequirements.length == 0,\n        \"allowMultiple options cannot expand or have implicit requirements\");\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["allowMultiple means 'collect values into a List' — nothing else; keep such options free of expansion/implicitRequirements.","Split aliasing behavior into a separate Void expansion option."],"tags":["java","bazel","annotation-processing","options","compile-time","allow-multiple","expansion"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}