# Null-safety and Java reflection

**URL:** <https://discuss.kotlinlang.org/t/null-safety-and-java-reflection/8525>\
**Category:** Support\
**Created:** [July 11, 2018, 3:30pm UTC](https://discuss.kotlinlang.org/t/null-safety-and-java-reflection/8525 "2018-07-11T15:30:28Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![jstuyts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstuyts/32/2141_2.png) [@jstuyts](https://discuss.kotlinlang.org/u/jstuyts)\
**Post date:** [July 16, 2018, 5:47am UTC](https://discuss.kotlinlang.org/t/null-safety-and-java-reflection/8525/21 "2018-07-16T05:47:42Z")

</div>

Here are my observations about the way you communicate:

- You seem to think that you are entitled to the community taking your (current) issue seriously, even though the fault lies with you: You need to understand how Java and Kotlin work, and how they intteroperate, and you need to deisgn your code so it works properly.
- Kotlin does not provide the features you want from a language. But you are not forced to use Kotlin, so it is your decision to use Kotlin that is the problem here. Not Kotlin.
- You claim that Kotlin was badly designed, not considering the enormous amount of thought, community particpation and work that went into this design.
- You complain about the people and the community who want to genuinely help you understand why it work the way it does, because it does not work the way you want it to.

---

<div class="post-metadata">

**Author:** ![jstuyts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstuyts/32/2141_2.png) [@jstuyts](https://discuss.kotlinlang.org/u/jstuyts)\
**Post date:** [July 16, 2018, 5:59am UTC](https://discuss.kotlinlang.org/t/null-safety-and-java-reflection/8525/22 "2018-07-16T05:59:00Z")

</div>

> [@Wasabi375](#):
>
> Jstuyts, reimagrab and I all 3 were not really following the community guide lines by being not all to nice to each other, […]

I don’t think my remark was out of place. It was not my genuine feeling, but it was stated in a nice way.

> [@Wasabi375](#):
>
> […], as we do run into a NPE (which kotlin supposedly fixes).

Where does it say that Kotlin fixes NPEs? Kotlin has better handling of nullability, but I don’t believe there was ever a statement about Kotlin fixing NPEs.

Should a language protect developers against themselves, even if they perfom unsupported actions that violate the language rules and the compiler cannot possibly know about?

Yes, the NPE with the elvis operator can be fixed by the compiler adding checks for `null` every time a non-nullable variable is accessed. But I know that this will lead to lots of people complaining that Kotlin uselessly checks for `null`.

A language has rules, you should learn them to correctly and effectively use the language. If you don’t like the language rules, you can suggest an improvement. But if the language does not evolve into what you want, you don’t start making claims that is is bad, the community is bad, etc.

---

<div class="post-metadata">

**Author:** ![sebdeleuze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/sebdeleuze/32/2196_2.png) [@sebdeleuze](https://discuss.kotlinlang.org/u/sebdeleuze)\
**Post date:** [July 16, 2018, 10:03am UTC](https://discuss.kotlinlang.org/t/null-safety-and-java-reflection/8525/23 "2018-07-16T10:03:19Z")

</div>

> Since Spring is just using Java reflection

This is incorrect. As of version 5.0, Spring Framework leverage Kotlin reflection and even provides a full null-safe API, see [Redirecting...](https://docs.spring.io/spring/docs/current/spring-framework-reference/languages.html#kotlin-null-safety).

---

<div class="post-metadata">

**Author:** ![reimagrab](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/reimagrab/32/5327_2.png) [@reimagrab](https://discuss.kotlinlang.org/u/reimagrab)\
**Post date:** [July 16, 2018, 12:29pm UTC](https://discuss.kotlinlang.org/t/null-safety-and-java-reflection/8525/24 "2018-07-16T12:29:56Z")

</div>

Thanks, for the link.  
Unfortunately:  
“Generic type arguments, varargs and array elements nullability are not supported yet”

---

<div class="post-metadata">

**Author:** ![sebdeleuze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/sebdeleuze/32/2196_2.png) [@sebdeleuze](https://discuss.kotlinlang.org/u/sebdeleuze)\
**Post date:** [July 16, 2018, 1:27pm UTC](https://discuss.kotlinlang.org/t/null-safety-and-java-reflection/8525/25 "2018-07-16T13:27:00Z")

</div>

Indeed, and we are working with JetBrains to support these use cases as well.

[Previous page](https://discuss.kotlinlang.org/t/null-safety-and-java-reflection/8525.md?page=1)
