kosi-libs / MocKMP

A mocking processor for Kotlin Multiplatform
https://kosi-libs.org/mockmp
MIT License
183 stars 12 forks source link

Getting NullPointerExceptions #39

Closed benkuly closed 1 year ago

benkuly commented 1 year ago

We have a bunch of tests flickering because sometimes MocKMP throws a NullPointerException:

java.lang.NullPointerException
    at org.kodein.mock.Mocker.process(Mocker.kt:76)
    at org.kodein.mock.Mocker.registerSuspend(Mocker.kt:309)
    at org.kodein.mock.Mocker.registerSuspend$default(Mocker.kt:148)
SalomonBrys commented 1 year ago

We need more information to address this.

benkuly commented 1 year ago

Are you using !! in MockKMP? I think this should be replaced with requreNotNull(value){"reason"} or save navigation ?. to avoid NullPointerExceptions, which are really hard to debug.

SalomonBrys commented 1 year ago

We really need a reproducer for this.

benkuly commented 1 year ago

I know. Our CI did not run much the last month to see the issue again. It is not reliably reproducible, only happens every few times. I remember, that when I tried to debug it the last time it came from a part of MockKMP where !! is used.

benkuly commented 1 year ago

Just wanted to inform you, that the issue still appears randomly. Unfortunately in a non-public project.

java.lang.NullPointerException
    at org.kodein.mock.Mocker.process(Mocker.kt:76)
    at org.kodein.mock.Mocker.registerSuspend(Mocker.kt:309)
    at org.kodein.mock.Mocker.registerSuspend$default(Mocker.kt:148)
    ...
    at org.kodein.mock.Mocker.verifyWithSuspend(Mocker.kt:234)
    at org.kodein.mock.Mocker.verifyWithSuspend$default(Mocker.kt:233)
SalomonBrys commented 1 year ago

I've removed all !! in version 1.12.0 and replaced them either with safe access (which should fix this issue) or with more semantic exceptions (which will not fix this issue, but provide a more semantic stack trace). I'll close this in the hope that the situation is the former. If it is the later, please re-open this issue.

benkuly commented 1 year ago

Thank you very much :)