InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
9.08k stars 719 forks source link

ClassCastException in TimeSource.getTimeSource() #1733

Closed RockieHUN closed 2 days ago

RockieHUN commented 11 months ago

Describe the bug ClassCastException\n at THROW_CCE (http://localhost:3000/node_modules/.vite/deps/apilib_packages_apilib.js?v=8a948aaf:4829:15) at getTimeSource (http://localhost:3000/node_modules/.vite/deps/apilib_packages_apilib.js?v=8a948aaf:16213:82) at protoOf.u1s (http://localhost:3000/node_modules/.vite/deps/apilib_packages_apilib.js?v=8a948aaf:16253:16) at protoOf.r1s (http://localhost:3000/node_modules/.vite/deps/apilib_packages_apilib.js?v=8a948aaf:15319:52) at protoOf.r1s (http://localhost:3000/node_modules/.vite/deps/apilib_packages_apilib.js?v=8a948aaf:15360:20) at koinApplication (http://localhost:3000/node_modules/.vite/deps/apilib_packages_apilib.js?v=8a948aaf:16160:28)

To Reproduce We have a Lightning Js project which uses a kotlin multiplatform library with Koin. Created an IsolatedKoinContext to avoid conflicts if a client app (android) uses Koin as well.

class IsolatedKoinContext {
    @Volatile
    var koin: Koin? = null
    protected val koinApp: KoinApplication = koinApplication()

    fun initKoin() {
        koin = koinApp.koin
    }

    fun addModules(modules: List<Module>) {
        koinApp.modules(modules)
    }
}

At app start, the application crashes with ClassCastException at somewhere in TimeSource.getTimeSource(). Can't tell exactly in which row. If I set createEagerInstances = false it works fine. Also with React Js, we don't have this problem. What is exactly the scope of eager instances?

Expected behavior Should not crash

Koin module and version: koin-core:3.5.0

arnaudgiuliani commented 9 months ago

could you provide a project sample or a snippet to help reproduce?