Return an empty collection instead of null
ProprietaryRewrites a bare return null; to return an empty immutable collection when the enclosing method's declared return type is java.util.List, java.util.Set, java.util.Collection, or java.util.Map (raw or generic): List and Collection become Collections.emptyList(), Set becomes Collections.emptySet(), and Map becomes Collections.emptyMap() (each statically imported). Returning an empty collection rather than null spares every caller a null check, but a caller that distinguishes null from empty observes a different result, so this is a behavior change and every rewritten return is flagged for review. Only the literal return null; statement is rewritten — a return someNullableExpr; is left untouched — and a method whose return is annotated @Nullable is skipped, since there the null is intended. The recipe is gated on @NullMarked scope, idempotent, and conservative; only Java sources are modified.
io. moderne. nullability. ReturnEmptyCollectionInsteadOfNullOptional
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. ReturnEmptyCollectionInsteadOfNullInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.