# @NonNull member variable is still null before completion of object construction

**URL:** <https://discuss.kotlinlang.org/t/nonnull-member-variable-is-still-null-before-completion-of-object-construction/15291>\
**Category:** Language Design\
**Created:** [December 4, 2019, 11:51am UTC](https://discuss.kotlinlang.org/t/nonnull-member-variable-is-still-null-before-completion-of-object-construction/15291 "2019-12-04T11:51:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adherencegoo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/adherencegoo/32/5109_2.png) [@adherencegoo](https://discuss.kotlinlang.org/u/adherencegoo)\
**Post date:** [December 4, 2019, 11:51am UTC](https://discuss.kotlinlang.org/t/nonnull-member-variable-is-still-null-before-completion-of-object-construction/15291/1 "2019-12-04T11:51:25Z")

</div>

```auto
class A {
    init {
// println(str) // compile time error: variable `str` must be initialized
        logContent() // no compile error, but `str` is `null` at this moment
    }
    
    val str = ""
    
    private fun logContent() {
        println(str)
    }
}

fun main() {
    A() // print: null
}

```

I know that this is logically wrong.  
But, no compile time error, is this a bug of Kotlin ?

---

<div class="post-metadata">

**Author:** ![al3c](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@al3c](https://discuss.kotlinlang.org/u/al3c)\
**Post date:** [December 4, 2019, 1:22pm UTC](https://discuss.kotlinlang.org/t/nonnull-member-variable-is-still-null-before-completion-of-object-construction/15291/2 "2019-12-04T13:22:46Z")

</div>

See:

> [@NRE from an "uninitialized this" in constructor](https://discuss.kotlinlang.org/t/nre-from-an-uninitialized-this-in-constructor/1966/8):
>
> Where compiler should report error, on call bar() on inside body of bar at c.length? Which function calls should be checked by compiler – only private inline? Actually there is no difference in that case between private inline and all others functions that have reference to leaking this (member or not) What if bar calls some other member function, that possibly access uninitialized c? Should compiler checks it’s body too? Actually, as @Wasabi375 described, it’s possible to add such “cross-func…
