Wrap nullable dereferenced values in requireNonNull

Proprietary

Wraps in java.util.Objects.requireNonNull(...) (statically imported) a provably-nullable value that is being dereferenced — the receiver of a method call (x.foo()), the target of a field access (x.field, including x.length), the base of an array index (x[i]), the qualifier of a method reference (x::foo), the outer instance of a qualified new, or the lock of a synchronized (x). Inside an annotated scope NullAway treats such a dereference as an error because it throws NullPointerException when the value is null; requireNonNull throws exactly when the dereference already would, so runtime behavior is unchanged. The value's nullness is resolved by attribution from the nullability model and a path-sensitive flow analysis (a value already null-checked on the path is not flagged). A .class literal, a type or package qualifier, a primitive, and a throw expression are never touched. 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.WrapNullableDereferenceInRequireNonNull

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.WrapNullableDereferenceInRequireNonNull

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