Annotate methods which may return null with @Nullable
MSALAdd @Nullable to public methods that may return null. By default org.jspecify.annotations.Nullable is used, but through the nullableAnnotationClass option a custom annotation can be provided. Both @Target(TYPE_USE) and declaration annotations (e.g. javax.annotation.CheckForNull) are supported. Methods that already carry a known nullable annotation (matched by simple name) are skipped to avoid duplication. This recipe scans for methods that do not already have a @Nullable annotation and checks their return statements for potential null values. It also identifies known methods from standard libraries that may return null, such as methods from Map, Queue, Deque, NavigableSet, and Spliterator. The return of streams, or lambdas are not taken into account.
org. openrewrite. staticanalysis. AnnotateNullableMethodsOptional
The fully qualified name of the @Nullable annotation to add. Both @Target(TYPE_USE) and declaration annotations (e.g. javax.annotation.CheckForNull) are supported. Defaults to org.jspecify.annotations.Nullable.
mod run . --recipe= org. openrewrite. staticanalysis. AnnotateNullableMethodsInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.