Home / Vulnerability Database / Kotlin : Incorrect comparison with NULL
Kotlin

Kotlin : Incorrect comparison with NULL

Classification

Overview



The application compares the object to null using equals(). Expression obj.equals(null) always returns false, because obj is not null (otherwise, there would be a NullPointerException).

== compares the object reference, if any, contained by a variable. .equals() checks to see if two objects are equal according to their contract for what equality means. It’s entirely possible for two distinct object instances to be “equal” according to their contract. And then there’s the minor detail that since equals is a method, if you try to invoke it on a null reference, you’ll get a NullPointerException. The traditional defense of this coding error is: “I know the requested value will always exist because…. If it does not exist, the program cannot perform the desired behavior so it doesn’t matter whether I handle the error or simply allow the program to die dereferencing a null value.” But attackers are skilled at finding unexpected paths through programs, particularly when exceptions are involved.

LOW

DerScanner Severity Score

Do you want to fix Kotlin : Incorrect comparison with NULL in your application?

See also

Kotlin

Kotlin : Missing required cryptographic step

Kotlin

Kotlin : Logging into system output

Kotlin

Kotlin : Call of notify() in synchronized block