Equals Null Call

ID

kotlin.equals_null_call

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Kotlin

Tags

npe, null-safety

Description

Reports x.equals(null) calls, which throw NullPointerException when the receiver is null.

The idiomatic Kotlin null-check is x == null, which uses the null-safe structural equality operator and never throws regardless of the receiver’s nullability.

Rationale

val x: String? = null

// Bad — throws NPE if x is null
if (x.equals(null)) { ... }  // FLAW

// Good — null-safe structural equality
if (x == null) { ... }

Remediation

Replace x.equals(null) with x == null.