Wrap a nullable for-each iterable in requireNonNull

Proprietary

Wraps the iterable of an enhanced-for (for-each) loop in java.util.Objects.requireNonNull(...) (statically imported) when it is a provably-nullable value. Inside an annotated scope NullAway treats the for-each iterable as non-null, so iterating a nullable expression is an error; iterating a null already throws NullPointerException when the loop obtains its iterator, so requireNonNull throws exactly where the loop already would and runtime behavior is unchanged. The iterable's nullness is resolved by attribution from the nullability model and a path-sensitive flow analysis. The fix never asserts non-null on a value that is genuinely nullable at the site. Idempotent and conservative; only Java sources are modified.

io.moderne.nullability.WrapNullableForEachIterableInRequireNonNull

Optional

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

The non-null assertion form to emit at a wrap site. AUTO (the default) emits Preconditions.checkNotNull in a file that already imports Guava's Preconditions, otherwise Objects.requireNonNull. CAST_TO_NON_NULL is explicit-only (it is suppression-like — no runtime throw) and never auto-selected.

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

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