# Throw NullPointerException when use kotlin 1.5.30

**URL:** <https://discuss.kotlinlang.org/t/throw-nullpointerexception-when-use-kotlin-1-5-30/22980>\
**Category:** Support\
**Created:** [September 19, 2021, 5:08pm UTC](https://discuss.kotlinlang.org/t/throw-nullpointerexception-when-use-kotlin-1-5-30/22980 "2021-09-19T17:08:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![monkey](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@monkey](https://discuss.kotlinlang.org/u/monkey)\
**Post date:** [September 19, 2021, 5:08pm UTC](https://discuss.kotlinlang.org/t/throw-nullpointerexception-when-use-kotlin-1-5-30/22980/1 "2021-09-19T17:08:06Z")

</div>

The same code，it works fine before . Now throw NullPointerException when use kotlin 1.5.30

```
open class Father {
private val bundle = mutableMapOf<String, Any>()

fun <V : Any> Class<V>.getMapValue(key: String): V? = when {
    this == java.lang.Integer::class.java || this == Int::class.java -> (bundle[key]?.toString()
        ?.toIntOrNull() ?: 0) as? V
    this == java.lang.String::class.java -> (bundle[key]?.toString() ?: "") as V
    this == java.lang.Boolean::class.java || this == Boolean::class.java -> (bundle[key]?.toString()
        ?.toBooleanStrictOrNull() ?: false) as? V
    else -> bundle[key] as? V
}

fun <V : Any> setValue(key: String, value: V): V? {
    return bundle.put(key, value) as? V
}

protected inline operator fun <reified V : Any> Father.setValue(
    thisRef: Any?,
    property: KProperty<*>,
    value: V?
): V? {
    return value?.let {
        setValue(property.name, it)
    }
}

protected inline operator fun <reified V : Any> Father.getValue(
    thisRef: Any?,
    property: KProperty<*>
): V {
    val v = V::class.java.getMapValue(property.name)
    return v ?: throw NullPointerException("no key ${property.name} found in map")
}

}
class Child : Father() {
var age: Int by this
var sex: Boolean by this
var addr: String by this
override fun toString(): String {
    return "{age:$age,sex:$sex,addr:$addr}"
  }
}

```

then i decompiler the child class，it shows that KProperty object allways null

 ![image](https://us1.discourse-cdn.com/flex019/uploads/kotlinlang/original/2X/6/6ffd0495395a59aae8e0144f95a477f74b4150a6.png)

---

<div class="post-metadata">

**Author:** ![Alexey.Belkov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexey.belkov/32/5215_2.png) [@Alexey.Belkov](https://discuss.kotlinlang.org/u/Alexey.Belkov)\
**Post date:** [September 20, 2021, 8:08am UTC](https://discuss.kotlinlang.org/t/throw-nullpointerexception-when-use-kotlin-1-5-30/22980/2 "2021-09-20T08:08:51Z")

</div>

Can you please share how to reproduce the NPE, for example your `main` function?

---

<div class="post-metadata">

**Author:** ![monkey](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@monkey](https://discuss.kotlinlang.org/u/monkey)\
**Post date:** [September 20, 2021, 11:19am UTC](https://discuss.kotlinlang.org/t/throw-nullpointerexception-when-use-kotlin-1-5-30/22980/3 "2021-09-20T11:19:06Z")

</div>

> [@Alexey.Belkov](#):
>
> ‎请您分享如何复制 NPE，例如您的功能？‎ `main`

Just instance a child object and access the feild，example

```
object Main {
@JvmStatic
fun main(args: Array<String>) {
    val son = Child()
    son.age = 23
   }
}

```

will throw exception

```auto
Exception in thread "main" java.lang.NullPointerException
	at com.example.myapplication.Child.setAge(Main.kt:61)
	at com.example.myapplication.Main.main(Main.kt:9)

```

---

<div class="post-metadata">

**Author:** ![Alexey.Belkov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexey.belkov/32/5215_2.png) [@Alexey.Belkov](https://discuss.kotlinlang.org/u/Alexey.Belkov)\
**Post date:** [September 20, 2021, 1:09pm UTC](https://discuss.kotlinlang.org/t/throw-nullpointerexception-when-use-kotlin-1-5-30/22980/4 "2021-09-20T13:09:55Z")

</div>

Thank you, I have created a bug report [https://youtrack.jetbrains.com/issue/KT-48825](https://youtrack.jetbrains.com/issue/KT-48825), please watch it for updates.
