https://kotlinlang.org logo
Title
u

Uldis Indriksons

09/05/2018, 8:33 AM
Question about null-safe call on nullable property. In our team we were discussing null-safety topic and wondering how kotlin
.?
works. So we decompiled it using AndroidStudio. The outcome was unexpected for us. The class:
class NullSafeCall {

    var nullableString: String? = null

    fun nullSafe() {
        nullableString?.length
    }
}
Decompiled
nullSafe
method:
public final void nullSafe() {
      String var10000 = this.nullableString;
      if (this.nullableString != null) {
         var10000.length();
      }
   }
It looks to me it can still get NPE as a result of nasty race-condition. Can someone explain to me wether it’ s kotlin issue or decompiler output is not quite accurate.
s

spand

09/05/2018, 8:41 AM
I think the decompiler is wrong. The bytecode looks ok to me
👍 3
u

Uldis Indriksons

09/05/2018, 10:37 AM
Thanks