Extract a repeated @Nullable invocation into a local variable
ProprietaryWhen the same side-effect-free @Nullable method invocation (textually identical receiver, name, and no arguments — e.g. source.get()) appears two or more times in one block, hoists it into a single local @Nullable Type x = source.get(); declared just before the first use and replaces every occurrence with x. NullAway cannot refine a @Nullable return across two separate calls — the second could return a different value — so if (source.get() != null) { source.get().foo(); } is rejected; one local gives the checker a single narrowing point. The rewrite is strictly gated: the call must be provably @Nullable (resolved from the nullability model), side-effect free (only a no-argument getter-style call whose receiver is a simple identifier or this, never an argument-bearing or unresolved-type call), all occurrences must be in the same block, and the receiver must not be reassigned anywhere in that block (which could change the value between calls). A pure call evaluated once rather than N times yields the same value, so runtime behavior is unchanged. Idempotent and conservative; only Java sources are modified.
io. moderne. nullability. ExtractRepeatedNullableInvocationToLocalOptional
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. ExtractRepeatedNullableInvocationToLocalInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.