Annotate required method parameters with @NonNull

MSAL

Add @NonNull to parameters of public methods that are explicitly checked for null and throw an exception if null. By default org.jspecify.annotations.NonNull is used, but through the nonNullAnnotationClass option a custom annotation can be provided. When providing a custom nonNullAnnotationClass that annotation should be meta annotated with @Target(TYPE_USE). This recipe scans for methods that do not already have parameters annotated with @NonNull annotation and checks for null validation patterns that throw exceptions, such as if (param == null) throw new IllegalArgumentException().

org.openrewrite.staticanalysis.AnnotateRequiredParameters

Optional

The fully qualified name of the @NonNull annotation. The annotation should be meta annotated with @Target(TYPE_USE). Defaults to org.jspecify.annotations.NonNull.

mod run . --recipe=org.openrewrite.staticanalysis.AnnotateRequiredParameters

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.