Kotlin 'unsafe call on nullable receiver' compile error after null check

2.1k views Asked by At

This is the screenshot of the error: Error Screenshot

I'm using Intellij v14.0.1 + Kotlin plugin v0.9.206. My understanding is that after the null check, the compiler shouldn't show me the error. Am I wrong?

2

There are 2 answers

1
user2235698 On BEST ANSWER

target property is var, that's why it's not guarantee that on the third line this property couldn't be null (e.g. another thread could set it to null)

3
maaartinus On

AFAIK, a property can be a method call and then nothing can be guaranteed. Use a local val.