question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InvalidMutabilityException caused by presenter injection

See original GitHub issue

Kodein 7.1.0 Kotlin 1.4.10 Ktor 1.4.1 Corutines 1.3.9-native-mt-2

Application is crashing on iOS, but on Android is working fine.

        super.init(
            contentView: NewDeviceContentView(),
            presenter: CommonLibraryInitializer.init().provideBeaconRegistrationPresenter(),
            coordinator: coordinator,
            shouldReattachWhenAppear: false
        )

fun provideBeaconRegistrationPresenter() = PresentationKodeinProvider.kodein.direct.instance<BeaconRegistrationPresenter>()

Uncaught Kotlin exception: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@887968
    at 0   CompanyCommon                      0x0000000105c359fd kfun:kotlin.Throwable#<init>(kotlin.String?){} + 93 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Throwable.kt:23:37)
    at 1   CompanyCommon                      0x0000000105c2e39b kfun:kotlin.Exception#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
    at 2   CompanyCommon                      0x0000000105c2e5eb kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
    at 3   CompanyCommon                      0x0000000105c6578b kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} + 91 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22:60)
    at 4   CompanyCommon                      0x0000000105c67042 ThrowInvalidMutabilityException + 690 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:92:11)
    at 5   CompanyCommon                      0x0000000105d64ddc MutationCheck + 108
    at 6   CompanyCommon                      0x0000000105c483e0 kfun:kotlin.collections.HashMap.<set-length>#internal + 80 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/collections/HashMap.kt:16:17)
    at 7   CompanyCommon                      0x0000000105c4cf7f kfun:kotlin.collections.HashMap#addKey(1:0){}kotlin.Int + 1231 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/collections/HashMap.kt:292:36)
    at 8   CompanyCommon                      0x0000000105c49483 kfun:kotlin.collections.HashMap#put(1:0;1:1){}1:1? + 355 (/Users/teamcity/buildAgent/work/cae0e6559deed4c4/runtime/src/main/kotlin/kotlin/collections/HashMap.kt:68:21)
    at 9   CompanyCommon                      0x0000000105ec1af7 kfun:org.kodein.di.bindings.StandardScopeRegistry#getOrCreate(kotlin.Any;kotlin.Boolean;kotlin.Function0<org.kodein.di.bindings.Reference.Local<kotlin.Any,org.kodein.di.bindings.Reference<kotlin.Any>>>){}kotlin.Any + 1447 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/scopes.kt:65:27)
    at 10  CompanyCommon                      0x0000000105ec77f2 kfun:org.kodein.di.bindings.Singleton.getFactory$lambda-3#internal + 546 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:22)
    at 11  CompanyCommon                      0x0000000105ec7ca4 kfun:org.kodein.di.bindings.Singleton.$getFactory$lambda-3$FUNCTION_REFERENCE$83.invoke#internal + 212 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:125:16)
    at 12  CompanyCommon                      0x0000000105ed9ab1 kfun:org.kodein.di.internal.DIContainerImpl.factory$lambda-2#internal + 241 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DIContainerImpl.kt:160:22)
    at 13  CompanyCommon                      0x0000000105eda5fc kfun:org.kodein.di.internal.DIContainerImpl.$factory$lambda-2$FUNCTION_REFERENCE$98.invoke#internal + 204 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DIContainerImpl.kt:160:20)
    at 14  CompanyCommon                      0x0000000105eb83d2 kfun:org.kodein.di.DIContainer.provider$<anonymous>_1#internal + 194 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/DIContainer.kt:23:1)
    at 15  CompanyCommon                      0x0000000105eb87dd kfun:org.kodein.di.DIContainer.$provider$<anonymous>_1$FUNCTION_REFERENCE$25.invoke#internal + 157 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/DIContainer.kt:22:37)
    at 16  CompanyCommon                      0x0000000105eec458 kfun:org.kodein.di.internal.DirectDIBaseImpl#Instance(org.kodein.type.TypeToken<0:0>;kotlin.Any?){0§<kotlin.Any>}0:0 + 984 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DirectDIImpl.kt:30:153)
    at 17  CompanyCommon                      0x0000000105815063 kfun:com.Company.data.di.deviceConnectionModule$lambda-35$lambda-0#internal + 963 (/Users/mateuszkrawczuk/android-Company-client/Company-mobile-multiplatform/data/src/commonMain/kotlin/com/Company/data/di/deviceConnectionModule.kt:64:52)
    at 18  CompanyCommon                      0x000000010582ec83 kfun:com.Company.data.di.$deviceConnectionModule$lambda-35$lambda-0$FUNCTION_REFERENCE$358.invoke#internal + 179 (/Users/mateuszkrawczuk/android-Company-client/Company-mobile-multiplatform/data/src/commonMain/kotlin/com/Company/data/di/deviceConnectionModule.kt:64:52)
    at 19  CompanyCommon                      0x0000000105ec7332 kfun:org.kodein.di.bindings.Singleton.getFactory$lambda-3$lambda-2$lambda-1#internal + 370 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:96)
    at 20  CompanyCommon                      0x0000000105ec7eb1 kfun:org.kodein.di.bindings.Singleton.$getFactory$lambda-3$lambda-2$lambda-1$FUNCTION_REFERENCE$84.invoke#internal + 161 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:67)
    at 21  CompanyCommon                      0x0000000105ebfd37 kfun:org.kodein.di.bindings.Reference.Local.Companion#invoke(kotlin.Function0<0:0>;kotlin.Function1<0:0,0:1>){0§<kotlin.Any>;1§<org.kodein.di.bindings.Reference<0:0>>}org.kodein.di.bindings.Reference.Local<0:0,0:1> + 343 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/references.kt:16:127)
    at 22  CompanyCommon                      0x0000000105ec0c4a kfun:org.kodein.di.bindings.Strong.Companion#make(kotlin.Function0<0:0>){0§<kotlin.Any>}org.kodein.di.bindings.Reference.Local<0:0,org.kodein.di.bindings.Strong<0:0>> + 330 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/references.kt:31:97)
    at 23  CompanyCommon                      0x0000000105ec7547 kfun:org.kodein.di.bindings.Singleton.getFactory$lambda-3$lambda-2#internal + 391 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:62)
    at 24  CompanyCommon                      0x0000000105ec80b1 kfun:org.kodein.di.bindings.Singleton.$getFactory$lambda-3$lambda-2$FUNCTION_REFERENCE$85.invoke#internal + 161 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:51)
    at 25  CompanyCommon                      0x0000000105ec19ee kfun:org.kodein.di.bindings.StandardScopeRegistry#getOrCreate(kotlin.Any;kotlin.Boolean;kotlin.Function0<org.kodein.di.bindings.Reference.Local<kotlin.Any,org.kodein.di.bindings.Reference<kotlin.Any>>>){}kotlin.Any + 1182 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/scopes.kt:64:43)
    at 26  CompanyCommon                      0x0000000105ec77f2 kfun:org.kodein.di.bindings.Singleton.getFactory$lambda-3#internal + 546 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:127:22)
    at 27  CompanyCommon                      0x0000000105ec7ca4 kfun:org.kodein.di.bindings.Singleton.$getFactory$lambda-3$FUNCTION_REFERENCE$83.invoke#internal + 212 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/bindings/standardBindings.kt:125:16)
    at 28  CompanyCommon                      0x0000000105ed9ab1 kfun:org.kodein.di.internal.DIContainerImpl.factory$lambda-2#internal + 241 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DIContainerImpl.kt:160:22)
    at 29  CompanyCommon                      0x0000000105eda5fc kfun:org.kodein.di.internal.DIContainerImpl.$factory$lambda-2$FUNCTION_REFERENCE$98.invoke#internal + 204 (/Users/runner/work/Kodein-DI/Kodein-DI/kodein-di/src/commonMain/kotlin/org/kodein/di/internal/DIContainerImpl.kt:160:20)
CoreSimulator 732.17 - Device: iPhone 8 (777479B4-8C83-494D-92DA-6EA9D0CE3133) - Runtime: iOS 14.1 (18A8394) - DeviceType: iPhone 8

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
romainbslcommented, Nov 14, 2020

Hi, Kodein-DI is working on Kotlin/Native and iOS, in fact we are using it in production.

What’s important here, is that it’s not compatible with the actual multithread memory model. This means, that it might ends badly if you try to share the same DI container across multiple threads. Otherwise, you should be fine.

Also, JetBrains is working hard to change that memory model for Kotlin/Native. It should land soon enough, so it might not worth the pain to make DI compatible anymore. We’d rather wait for the new memory model.

0reactions
romainbslcommented, Feb 15, 2021

Don’t hesitate to re-open if you still have some issues.

Note that for those kind of troubles, a reproducible test case helps a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

InvalidMutabilityException caused by presenter injection
This code was working before upgrading to Kotlin 1.4.10 and other libraries, but since upgrading I'm struggling with many bugs. PresenterImpl.
Read more >
mutation attempt of frozen <object> when using ktor in ...
Turns out that the Kotlin version 1.3.11 is causing the trouble. I have downgraded it to 1.3.10 and it works perfectly fine. ktor...
Read more >
Frozen during lazy computation" when using by ...
To achieve mutable XOR global invariant, all globally visible state (currently, object singletons and enums) are automatically frozen. If object freezing is not ......
Read more >
[Solved]-Attempt to migrate on canary 5-kotlin
If the answer is 'yes', try to move them into the companion object, like so: class CloudStore { companion object { private const...
Read more >
Memory Leak Kotlin Native Library In Ios - ADocLib
I've encountered a memory leak which I believe is caused by a race ... to your old buddy InvalidMutabilityException as you'll stop seeing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found