Why this matters
Idiomatic null handling reduces branching, clarifies intent, and prevents NullPointerException.
Use safe calls (?.), the Elvis operator (?:), let/run/also for scoped handling, and early returns for invalid input.
Idiomatic null handling reduces branching, clarifies intent, and prevents NullPointerException.
Side-by-side examples engineers can pattern-match during review.
if (user != null) { process(user) } else { /* later... */ }val name = user?.name ?: return
user.email?.let { sendEmail(it) }if (x != null) do(x) else {/*...*/}x?.let { do(it) } ?: returnFrom the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.