{"record":{"id":"9445d7c742d77e83","repo":"bazelbuild/bazel","slug":"option-must-have-an-actual-name","errorCode":null,"errorMessage":"Option must have an actual name.","messagePattern":"Option must have an actual name\\.","errorType":"validation","errorClass":"OptionProcessorException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/processor/OptionsClassProcessor.java","lineNumber":357,"sourceCode":"      throw new OptionProcessorException(\n          method, \"Annotated method name must start with 'get' followed by an uppercase letter\");\n    }\n\n    checkOptionName(method);\n    checkOldCategoriesAreNotUsed(method);\n    checkExpansionOptions(method);\n    checkConverter(method);\n    checkEffectTagRationality(method);\n    checkMetadataTagAndCategoryRationality(method);\n    checkNoDefaultValueForMultipleOption(method);\n    checkDeprecated(method);\n  }\n\n  private void checkOptionName(ExecutableElement method) throws OptionProcessorException {\n    Option annotation = method.getAnnotation(Option.class);\n    String optionName = annotation.name();\n    if (optionName.isEmpty()) {\n      throw new OptionProcessorException(method, \"Option must have an actual name.\");\n    }\n\n    if (!ImmutableList.copyOf(annotation.metadataTags()).contains(OptionMetadataTag.INTERNAL)) {\n      if (!Pattern.matches(\"([\\\\w:-])*\", optionName)) {\n        // Ideally, this would be just \\w, but - and : are needed for legacy options. We can lie in\n        // the error though, no harm in encouraging good behavior.\n        throw new OptionProcessorException(\n            method,\n            \"Options that are used on the command line as flags must have names made from word \"\n                + \"characters only.\");\n      }\n    }\n  }\n\n  private void checkEffectTagRationality(ExecutableElement method) throws OptionProcessorException {\n    Option annotation = method.getAnnotation(Option.class);\n    OptionEffectTag[] effectTags = annotation.effectTags();\n    if (effectTags.length < 1) {","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/processor/OptionsClassProcessor.java#L339-L375","documentation":"The options annotation processor rejects an @Option annotation whose name attribute is the empty string. Every registered option needs a concrete flag name because the name is the key used for command-line lookup, expansion, and serialization; the processor enforces this at compile time before any code generation.","triggerScenarios":"Writing @Option(name = \"\", ...) or omitting a meaningful name while relying on some default that does not exist — the name has no implicit derivation from the method.","commonSituations":"Copying an annotation template and forgetting to fill in the name; refactor scripts that strip annotation values; assuming the flag name defaults to the method name.","solutions":["Set an explicit name: @Option(name = \"my_flag\", ...)","Choose the exact CLI spelling you want (snake_case by convention) since the name will not be derived from the getter","Recompile to let the remaining checks (name charset, effect tags) run"],"exampleFix":"// before\n@Option(name = \"\", defaultValue = \"x\", effectTags = {OptionEffectTag.NO_OP})\nString getFoo();\n// after\n@Option(name = \"foo\", defaultValue = \"x\", effectTags = {OptionEffectTag.NO_OP})\nString getFoo();","handlingStrategy":"validation","validationCode":"// Ensure every @Option declares a non-empty name\nfor (var m : MyOptions.class.getMethods()) {\n  Option o = m.getAnnotation(Option.class);\n  if (o != null && o.name().isEmpty()) {\n    throw new AssertionError(\"@Option on \" + m + \" has empty name\");\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write name explicitly; there is no derivation from the method","Use annotation templates with a placeholder that fails visibly if unfilled"],"tags":["bazel","options","annotation-processor","compile-time","java"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}