generate @CheckReturnValue annotations
- Dominant language
- Java
- Stars
- 10.6k
- Forks
- 1.2k
- Avg merge
- 6h 32m
- Merged PRs (30d)
- 13
Description
It would be useful to have the `@CheckReturnValue` annotation automatically be added to the AutoValue generated getters and builder methods. Calling these without using their return value (i.e. writing them as statement) is probably always an error (e.g. configuring a builder, but never actually building the final object).
The CheckReturnValue annotation is validated at least by [errorprone](https://errorprone.info/bugpattern/CheckReturnValue) and [spotbugs](https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#rv-method-ignores-return-value-is-this-ok-rv-return-value-ignored-inferred). To my knowledge both tools care only about the simple class name, therefore the annotation could be cloned into the AutoValue annotations namespace, to not create a dependency to any of those tools.
Currently the developer can add the annotation to the AutoValue fields and they will be copied (so there is a workaround for the getters). However, it seems impossible to have the annotation at the generated builder methods. With our without using `@AutoValue.CopyAnnotations` they are missing from the generated code.
Contributor guide
Assessment
This issue has not been assessed yet.