# Nullable value causes NullPointerException

**URL:** <https://discuss.kotlinlang.org/t/nullable-value-causes-nullpointerexception/18134>\
**Category:** Support\
**Created:** [June 18, 2020, 5:24am UTC](https://discuss.kotlinlang.org/t/nullable-value-causes-nullpointerexception/18134 "2020-06-18T05:24:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lber19535](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@lber19535](https://discuss.kotlinlang.org/u/lber19535)\
**Post date:** [June 18, 2020, 5:24am UTC](https://discuss.kotlinlang.org/t/nullable-value-causes-nullpointerexception/18134/1 "2020-06-18T05:24:15Z")

</div>

```
val a:Boolean? = false
// if I set break point here and set a = null,
// then resume program will show NullPointerException
1.run {
    a?.let { false } // line 104
}.apply {
    println(a)
}

```

Exception in thread “main” java.lang.NullPointerException  
at TestKt.main(Test.kt:104)  
at TestKt.main(Test.kt)

What causes this NullPointerException?

---

<div class="post-metadata">

**Author:** ![gidds](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/gidds/32/10865_2.png) [@gidds](https://discuss.kotlinlang.org/u/gidds)\
**Post date:** [June 18, 2020, 7:07am UTC](https://discuss.kotlinlang.org/t/nullable-value-causes-nullpointerexception/18134/2 "2020-06-18T07:07:38Z")

</div>

Perhaps the compiler can see that the value cannot\* be null at that point, and so treats the `.?` safe-call like a normal `.` call?

(\* Cannot — except for ‘impossible’ situations like changing it in a debugger…)

By the way, it would be helpful if you could [post the code as text](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question), not an image.

---

<div class="post-metadata">

**Author:** ![lber19535](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@lber19535](https://discuss.kotlinlang.org/u/lber19535)\
**Post date:** [June 18, 2020, 8:02am UTC](https://discuss.kotlinlang.org/t/nullable-value-causes-nullpointerexception/18134/3 "2020-06-18T08:02:20Z")

</div>

Thanks for your reply!

In real project, the location of “1” and “a” are two function, they will return the same type value, so I need “?.” for null safety, but when “a” return null, the NullPointerException will happen
