Why this matters
Avoids ambiguous nulls and clarifies API contracts.
When using Optional/CompletableFuture/Publisher-like types, map empty values to a clear outcome (e.g., 404) rather than returning null.
Avoids ambiguous nulls and clarifies API contracts.
Side-by-side examples engineers can pattern-match during review.
Optional<User> u = repo.find(id); return u.orElse(null);return repo.find(id).map(this::ok).orElseGet(() -> notFound());future.thenApply(x -> null)optional.map(this::ok).orElseGet(this::notFound)From the same buckets as this rule.