Add @Nullable to a method that can return null

Proprietary

Adds JSpecify @Nullable to a method or lambda whose effective return type is non-null but that returns a provably-nullable value, a NullAway error inside a @NullMarked scope. A regular method has its return type widened to JSpecify @Nullable in the type-use position; when the non-null return contract cannot be widened (an override of a non-null return of a library supertype in an annotated scope, or a lambda whose functional-interface return is non-null) the returned expression is wrapped in java.util.Objects.requireNonNull(...) instead, leaving runtime behavior unchanged. Nullability is determined from type attribution, and an unconditional return null is left for a human. The recipe is idempotent and conservative; only Java sources are modified.

io.moderne.nullability.AddNullableToNullReturningMethod

Optional

Comma-separated package prefixes to limit the fix to (matching NullAway's AnnotatedPackages option). When unset, the recipe fixes all packages.

mod run . --recipe=io.moderne.nullability.AddNullableToNullReturningMethod

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