Using !! on a nullable variable that turned out to be null at runtime.
Kotlin's type system distinguishes nullable (`String?`) from non-null (`String`) types. Using the double-bang `!!` operator explicitly promises the compiler a variable is not null. If it is null, Kotlin throws a `NullPointerException`.
Bypassing Kotlin's compile-time null safety using `!!` on variables populated asynchronously or from external Java libraries.
1fun main() {2 val email: String? = getNullableEmail()3 // Explicitly asserting email is not null!4 println(email!!.length) // Throws NullPointerException!5}6 7fun getNullableEmail(): String? = null1fun main() {2 val email: String? = getNullableEmail()3 4 // Fix 1: Safe call operator (?.) with Elvis operator (?:)5 val length = email?.length ?: 06 println("Email length: $length")7 8 // Fix 2: Safe let block9 email?.let { nonNullEmail ->10 println("Email: $nonNullEmail")11 }12}13 14fun getNullableEmail(): String? = nullSimulate standard system builds to trigger compiler trace records and track memory crashes locally.
Variable `email` holds `null`. Using `email!!` disables safe checks and forces an immediate runtime `NullPointerException`.