Route a guarded raw accessor through its present Optional

Proprietary

Inside the then-branch of an if (xOpt().isPresent()) { ... } guard, rewrites a sibling raw nullable accessor getX() to xOpt().get(), so the checker flows non-null through the Optional instead of needing a requireNonNull. NullAway flags the bare getX() dereference because the accessor is @Nullable, but the enclosing isPresent() guard already proves the corresponding Optional is present; reading through xOpt().get() re-expresses the same value via the guarded, provably-present Optional. The rewrite is gated for correctness over coverage: the guard must be exactly <recv>.isPresent() on a no-argument, side-effect-free Optional accessor; the rewritten getX() must be the matching no-argument raw accessor (same enclosing receiver, and <recv> named getX plus an Optional suffix) that is provably @Nullable here; and the use must be lexically inside the then-block so the guard dominates it. Because the Optional is proven present in the guarded branch, .get() cannot throw where the raw accessor did not, so runtime behavior is unchanged. Idempotent and conservative; only Java sources are modified.

io.moderne.nullability.CollapseOptionalPresentGuardToGet

Optional

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

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