Hoist a guarded @Nullable field read into a local variable

Proprietary

NullAway cannot refine a @Nullable field across a dereference, because the field could be mutated between the null check and the use, so if (this.f != null) { this.f.foo(); } is rejected. This recipe reads the field into a local once before the if — String f = this.f; if (f != null) { f.foo(); } — which NullAway can refine. Only a @Nullable instance field of the enclosing class, guarded by a != null check, is rewritten, and only in the condition and the then-block. The field must not be reassigned in the then-block, nor named without this. in the else part or later in the block, where the local would capture it.

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

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