Why this matters
Null assertions crash at runtime and hide intent. Explicit handling makes failure modes predictable and testable.
Avoid the !! operator. Prefer safe calls, Elvis (?:), early returns, or explicit exceptions with a clear message.
Null assertions crash at runtime and hide intent. Explicit handling makes failure modes predictable and testable.
Side-by-side examples engineers can pattern-match during review.
val len = name!!.lengthval len = name?.length ?: return Result.failure(IllegalArgumentException("name is required"))user!!.emailval email = user?.email ?: throw IllegalStateException("missing email")From 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.