{"record":{"id":"473a3c185190a092","repo":"bazelbuild/bazel","slug":"annotated-method-name-must-start-with-get-follow","errorCode":null,"errorMessage":"Annotated method name must start with 'get' followed by an uppercase letter","messagePattern":"Annotated method name must start with 'get' followed by an uppercase letter","errorType":"validation","errorClass":"OptionProcessorException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/google/devtools/common/options/processor/OptionsClassProcessor.java","lineNumber":339,"sourceCode":"      messager.printMessage(\n          Diagnostic.Kind.ERROR,\n          \"Failed to generate implementation for \" + className + \": \" + e.getMessage());\n    }\n  }\n\n  private void checkMethodOption(ExecutableElement method) throws OptionProcessorException {\n    if (!method.getModifiers().contains(Modifier.PUBLIC)) {\n      throw new OptionProcessorException(method, \"@Option method must be public\");\n    }\n    if (!method.getModifiers().contains(Modifier.ABSTRACT)) {\n      throw new OptionProcessorException(method, \"@Option method must be abstract\");\n    }\n\n    String methodName = method.getSimpleName().toString();\n    if (!methodName.startsWith(\"get\")\n        || methodName.length() < 4\n        || !Character.isUpperCase(methodName.charAt(3))) {\n      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.\");","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/bazelbuild/bazel/blob/e6e199d0601a244511b4cf18c8b2828aa73db1fd/src/main/java/com/google/devtools/common/options/processor/OptionsClassProcessor.java#L321-L357","documentation":"The options annotation processor enforces a naming convention on @Option interface methods: the name must start with 'get', be at least 4 characters, and the 4th character (index 3) must be uppercase — the standard Java bean getter shape. This keeps the generated implementation and documentation consistent with the flag's accessors.","triggerScenarios":"Annotating methods like foo(), getfoo(), get(), or getFoo vs isFoo-style names — anything not matching get + Uppercase — with @Option in an options interface.","commonSituations":"Naming a getter after the flag without the get prefix (e.g. experimentalCxxFlags()); 'is' prefix for booleans (isFoo) which the convention rejects; abbreviation casing like getURL that starts lowercase after 'get'.","solutions":["Rename the method to getFoo / getFooBar form (get + flag name in CamelCase)","For booleans keep the get prefix too (getFoo, not isFoo) — the flag still uses --nofoo negation at the CLI level","Update call sites or add a delegating accessor elsewhere if you need a different public name"],"exampleFix":"// before\n@Option(name = \"foo\", effectTags = {OptionEffectTag.NO_OP})\nString foo();\n// after\n@Option(name = \"foo\", effectTags = {OptionEffectTag.NO_OP})\nString getFoo();","handlingStrategy":"validation","validationCode":"// Enforce the get+Uppercase convention in a build-time check\nvar NAME = java.util.regex.Pattern.compile(\"get[A-Z].*\");\nfor (var m : MyOptions.class.getMethods()) {\n  if (m.isAnnotationPresent(Option.class) && !NAME.matcher(m.getName()).matches()) {\n    throw new AssertionError(\"@Option method name must be getFoo-style: \" + m.getName());\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name the getter after the flag: flag foo_bar -> getFooBar()","Use get even for booleans","Let the IDE generate getters, then add the annotation"],"tags":["bazel","options","annotation-processor","compile-time","naming-convention","java"],"backgroundTag":null,"analyzedSha":"e6e199d0601a244511b4cf18c8b2828aa73db1fd","analyzedAt":"2026-08-14T10:24:27.848Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}