compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

java.lang.ClassCastException: class androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to class kotlin.jvm.functions.Function0

Open CLOVIS-AI opened this issue 2 years ago • 13 comments
trafficstars

Describe the bug

When using an interface which inherits from other interfaces which have @Composable default methods, the application immediately crashes at runtime with the following exception:

java.lang.ClassCastException: androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to kotlin.jvm.functions.Function0

The stack trace points to this code, which seems completely normal to me:

interface Foo : Style {
    // …
    
    @Composable
    override fun initializeThemeFor(
        theme: Theme,
        content: @Composable () -> Unit,
    ) {
        MaterialTheme {
            content()
        }
    }
}
Full Android stacktrace

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: opensavvy.decouple.demo.android, PID: 6525
    java.lang.ClassCastException: androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to kotlin.jvm.functions.Function0
        at opensavvy.decouple.material.MaterialUI.initializeFor(MaterialUI.kt:15)
        at opensavvy.decouple.core.Style$Companion$Install$1.invoke(Style.kt:71)
        at opensavvy.decouple.core.Style$Companion$Install$1.invoke(Style.kt:70)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at opensavvy.decouple.core.Style$Companion.Install(Style.kt:70)
        at opensavvy.decouple.demo.DemoKt.Demo(Demo.kt:51)
        at opensavvy.decouple.demo.android.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:15)
        at opensavvy.decouple.demo.android.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:14)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:404)
        at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:250)
        at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:249)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:177)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:123)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:122)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:114)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:157)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:156)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:156)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:140)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:78)
        at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3248)
        at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3238)
        at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:341)
        at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
E/AndroidRuntime:     at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3238)
        at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3173)
        at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:587)
        at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:950)
        at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:140)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
        at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1060)
        at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:131)
        at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:182)
        at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:314)
        at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.kt:192)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:138)
        at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
        at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:1147)
        at android.view.View.dispatchAttachedToWindow(View.java:20812)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3490)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2675)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2179)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8787)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1037)
        at android.view.Choreographer.doCallbacks(Choreographer.java:845)
        at android.view.Choreographer.doFrame(Choreographer.java:780)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1022)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7842)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Full Desktop stacktrace

Exception in thread "main" java.lang.ClassCastException: class androidx.compose.runtime.internal.ComposableLambdaImpl cannot be cast to class kotlin.jvm.functions.Function0 (androidx.compose.runtime.internal.ComposableLambdaImpl and kotlin.jvm.functions.Function0 are in unnamed module of loader 'app')
	at opensavvy.decouple.material.MaterialUI.initializeFor(MaterialUI.kt:15)
	at opensavvy.decouple.core.Style$Companion$Install$1.invoke(Style.kt:71)
	at opensavvy.decouple.core.Style$Companion$Install$1.invoke(Style.kt:70)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
	at opensavvy.decouple.core.Style$Companion.Install(Style.kt:70)
	at opensavvy.decouple.demo.DemoKt.Demo(Demo.kt:51)
	at opensavvy.decouple.demo.desktop.ComposableSingletons$MainKt$lambda-1$1.invoke(Main.kt:12)
	at opensavvy.decouple.demo.desktop.ComposableSingletons$MainKt$lambda-1$1.invoke(Main.kt:11)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.ui.awt.ComposeWindow$setContent$5.invoke(ComposeWindow.desktop.kt:126)
	at androidx.compose.ui.awt.ComposeWindow$setContent$5.invoke(ComposeWindow.desktop.kt:125)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.ui.awt.ComposeWindowDelegate.WindowUserContentLayout(ComposeWindowDelegate.desktop.kt:203)
	at androidx.compose.ui.awt.ComposeWindowDelegate.WindowContentLayout(ComposeWindowDelegate.desktop.kt:162)
	at androidx.compose.ui.awt.ComposeWindowDelegate.access$WindowContentLayout(ComposeWindowDelegate.desktop.kt:48)
	at androidx.compose.ui.awt.ComposeWindowDelegate$setContent$3$1.invoke(ComposeWindowDelegate.desktop.kt:151)
	at androidx.compose.ui.awt.ComposeWindowDelegate$setContent$3$1.invoke(ComposeWindowDelegate.desktop.kt:150)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
	at androidx.compose.ui.awt.ComposeWindowDelegate$setContent$3.invoke(ComposeWindowDelegate.desktop.kt:147)
	at androidx.compose.ui.awt.ComposeWindowDelegate$setContent$3.invoke(ComposeWindowDelegate.desktop.kt:146)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
	at androidx.compose.ui.ComposeScene$setContent$5.invoke(ComposeScene.skiko.kt:371)
	at androidx.compose.ui.ComposeScene$setContent$5.invoke(ComposeScene.skiko.kt:370)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
	at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:177)
	at androidx.compose.ui.platform.Wrapper_skikoKt$setContent$2$1.invoke(Wrapper.skiko.kt:47)
	at androidx.compose.ui.platform.Wrapper_skikoKt$setContent$2$1.invoke(Wrapper.skiko.kt:46)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
	at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:248)
	at androidx.compose.ui.platform.Wrapper_skikoKt.provide(Wrapper.skiko.kt:61)
	at androidx.compose.ui.platform.Wrapper_skikoKt.access$provide(Wrapper.skiko.kt:1)
	at androidx.compose.ui.platform.Wrapper_skikoKt$setContent$2.invoke(Wrapper.skiko.kt:46)
	at androidx.compose.ui.platform.Wrapper_skikoKt$setContent$2.invoke(Wrapper.skiko.kt:45)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:37)
	at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3248)
	at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3238)
	at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:341)
	at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source)
	at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3238)
	at androidx.compose.runtime.ComposerImpl.composeContent$runtime(Composer.kt:3173)
	at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:587)
	at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:950)
	at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
	at androidx.compose.ui.platform.Wrapper_skikoKt.setContent(Wrapper.skiko.kt:45)
	at androidx.compose.ui.ComposeScene.setContent$ui(ComposeScene.skiko.kt:367)
	at androidx.compose.ui.ComposeScene.setContent$ui$default(ComposeScene.skiko.kt:346)
	at androidx.compose.ui.awt.ComposeLayer$setContent$3$1.invoke(ComposeLayer.desktop.kt:432)
	at androidx.compose.ui.awt.ComposeLayer$setContent$3$1.invoke(ComposeLayer.desktop.kt:431)
	at androidx.compose.ui.awt.ComposeLayer.catchExceptions(ComposeLayer.desktop.kt:109)
	at androidx.compose.ui.awt.ComposeLayer.access$catchExceptions(ComposeLayer.desktop.kt:87)
	at androidx.compose.ui.awt.ComposeLayer$setContent$3.invoke(ComposeLayer.desktop.kt:431)
	at androidx.compose.ui.awt.ComposeLayer$setContent$3.invoke(ComposeLayer.desktop.kt:430)
	at androidx.compose.ui.awt.ComposeLayer.initContent(ComposeLayer.desktop.kt:446)
	at androidx.compose.ui.awt.ComposeLayer.access$initContent(ComposeLayer.desktop.kt:87)
	at androidx.compose.ui.awt.ComposeLayer$ComponentImpl.addNotify(ComposeLayer.desktop.kt:226)
	at java.desktop/java.awt.Container.addNotify(Container.java:2804)
	at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4839)
	at androidx.compose.ui.awt.ComposeWindowDelegate$_pane$1.addNotify(ComposeWindowDelegate.desktop.kt:85)
	at java.desktop/java.awt.Container.addNotify(Container.java:2804)
	at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4839)
	at java.desktop/java.awt.Container.addNotify(Container.java:2804)
	at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4839)
	at java.desktop/java.awt.Container.addNotify(Container.java:2804)
	at java.desktop/javax.swing.JComponent.addNotify(JComponent.java:4839)
	at java.desktop/javax.swing.JRootPane.addNotify(JRootPane.java:729)
	at java.desktop/java.awt.Container.addNotify(Container.java:2804)
	at java.desktop/java.awt.Window.addNotify(Window.java:791)
	at java.desktop/java.awt.Frame.addNotify(Frame.java:495)
	at java.desktop/java.awt.Window.pack(Window.java:829)
	at androidx.compose.ui.util.Windows_desktopKt.makeDisplayable(Windows.desktop.kt:160)
	at androidx.compose.ui.window.Window_desktopKt$Window$11$1.invoke(Window.desktop.kt:392)
	at androidx.compose.ui.window.Window_desktopKt$Window$11$1.invoke(Window.desktop.kt:385)
	at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$3.invoke(AwtWindow.desktop.kt:83)
	at androidx.compose.ui.window.AwtWindow_desktopKt$AwtWindow$3.invoke(AwtWindow.desktop.kt:81)
	at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2$performUpdate$1.invoke(UpdateEffect.desktop.kt:59)
	at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2$performUpdate$1.invoke(UpdateEffect.desktop.kt:55)
	at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2140)
	at androidx.compose.runtime.snapshots.SnapshotStateObserver$observeReads$1$1.invoke(SnapshotStateObserver.kt:134)
	at androidx.compose.runtime.snapshots.SnapshotStateObserver$observeReads$1$1.invoke(SnapshotStateObserver.kt:130)
	at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:341)
	at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source)
	at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:130)
	at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2.invoke$performUpdate(UpdateEffect.desktop.kt:55)
	at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2.invoke(UpdateEffect.desktop.kt:64)
	at androidx.compose.ui.util.UpdateEffect_desktopKt$UpdateEffect$2.invoke(UpdateEffect.desktop.kt:47)
	at androidx.compose.runtime.DisposableEffectImpl.onRemembered(Effects.kt:81)
	at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:1091)
	at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:818)
	at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:839)
	at androidx.compose.runtime.Recomposer.composeInitial$runtime(Recomposer.kt:978)
	at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
	at androidx.compose.ui.window.Application_desktopKt$awaitApplication$2$1$2.invokeSuspend(Application.desktop.kt:219)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Affected platforms

  • Desktop → affected
  • Android → affected
  • Web (K/JS) → NOT affected, works fine
  • Other → not tested

If the bug is Android-only, report it in the Jetpack Compose tracker

Versions

  • Kotlin version*: 1.8.10
  • Compose Multiplatform version*: 1.3.1
  • OS version(s)* (required for Desktop and iOS issues): Linux 6.3.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 11 May 2023 16:40:42 +0000 x86_64 GNU/Linux
  • OS architecture (x86 or arm64): x86
  • JDK (for desktop issues): OpenJDK Runtime Environment (build 17.0.7+7)

To Reproduce

  1. git clone https://gitlab.com/opensavvy/decouple.git
  2. cd decouple
  3. git switch --detach 2970f435
  4. ./gradlew demo:desktop:run

As soon as compilation is over, a crash popup appears and the stack trace is displayed in the terminal. The application never starts.

To reproduce on Android, use the "Demo (Android)" run configuration provided with the project. To my knowledge, the setup is standard.

Expected behavior

The application starts (the home page is a wall of text with a bottom navigation bar).

Screenshots

The only thing that happens when starting the Desktop version (other than the stack trace in the standard output).

Screenshot_20230524_221525

Additional context

It seems to be linked to interface inheritance somehow. The offending commit converted objects which were used to implement an interface via interface delegation, to interfaces with default methods.

CLOVIS-AI avatar May 24 '23 20:05 CLOVIS-AI

There are other issues that give a similar stack trace, but they all seem different enough that I don't feel it's right to add my case there.

Similar issues

#1620 (not fixed)

  • Happens occasionally during tests. In my case, it happens 100% of the time when running the application. The tests run fine.

https://issuetracker.google.com/issues/261757203 (marked as fixed in Compose Compiler 1.4.4)

  • Relates to setContent being called in the offending file. I do not use it.
  • Says it is fixed in Compose Compiler 1.4.4. I have tried to upgrade my project to Kotlin 1.8.2 / Compose Multiplatform 1.4.0 (Compose Compiler 1.4.5), but the problem remains.

https://issuetracker.google.com/issues/254185294 (not fixed)

  • Seems related to the Fragments library, which I don't use.
  • The author says it disappears after a ./gradlew clean. In my case, a clean + full recompile without build cache doesn't fix the problem.
  • Seems to suggest adding an explicit dependency on the Compose runtime helps. I tried adding an explicit dependency in all modules on compose.runtime but it doesn't change anything.

https://issuetracker.google.com/issues/252471936 (not fixed, 17 votes)

  • Seems similar. The author provides two workarounds, but I cannot use them.

https://stackoverflow.com/questions/68083934

  • Seems to match with the previous issues. No issues are proposed.

https://issuetracker.google.com/issues/206013293 (not fixed, 12 votes)

  • Relates to passing lambdas to super constructors, which I'm not doing.
  • Only happens in incremental builds. Always happens in my case.

https://issuetracker.google.com/issues/185389423 (not fixed, 13 votes)

  • No workarounds

CLOVIS-AI avatar May 24 '23 20:05 CLOVIS-AI

Does interface Style contain Composable function with default arguments?

dima-avdeev-jb avatar May 25 '23 07:05 dima-avdeev-jb

Checked, it also reproduced with Compose 1.4.0 and Kotlin 1.8.20

dima-avdeev-jb avatar May 25 '23 08:05 dima-avdeev-jb

@CLOVIS-AI Can you please create a minimal reproducible sample of this problem on GitHub ? Because for now, there is a lot of code in your library, so it is hard to determine the exact reason.

dima-avdeev-jb avatar May 25 '23 08:05 dima-avdeev-jb

@dima-avdeev-jb I'd like to, but I don't know where to start to minize it. If you have any idea of what could be related, please tell me.

CLOVIS-AI avatar May 25 '23 12:05 CLOVIS-AI

I reproduced this bug in repository: https://github.com/dima-avdeev-jb/reproduce-bug-3205

dima-avdeev-jb avatar May 26 '23 06:05 dima-avdeev-jb

Just to add what I can—I am running into this without using Compose Multi-platform. Using purely Compose to write an Android app. Happens sometimes, but once it starts happening, it is consistent until I rebuild and get lucky, then it goes away.

stevepopovich avatar Jun 05 '23 15:06 stevepopovich

@stevepopovich I think there are multiple root causes. Are you using composables declared in interfaces? In the case described in this issue, it happens 100% of the time, even if I rebuild or do anything else. I haven't found any way to make the app run again.

CLOVIS-AI avatar Jun 05 '23 17:06 CLOVIS-AI

No, but there is inheritance and companion objects

stevepopovich avatar Jun 05 '23 17:06 stevepopovich

Hi @CLOVIS-AI ! Sorry for long time without any activity here. The good news is with new CM 1.5.10 and kotlin 1.9.20 there is no crash anymore. I applied this patch to your reproducer:

Index: gradle/libs.versions.toml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
--- a/gradle/libs.versions.toml	(revision 2970f435391c92cfe9927fc256b92684b575be7a)
+++ b/gradle/libs.versions.toml	(date 1699435904833)
@@ -1,11 +1,11 @@
 [versions]
-kotlin = "1.8.10"
+kotlin = "1.9.20"
 dokka = "1.7.20"
 android = "7.4.1"
 pedestal = "2.0.0-rc.3"
 
-compose = "1.3.1"
-compose-androidCompilerExtension = "1.4.2"
+compose = "1.5.10"
+compose-androidCompilerExtension = "1.5.4"
 
 kotlinx-coroutines = "1.6.4"
 kotlinx-datetime = "0.4.0"
Index: build.gradle.kts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/build.gradle.kts b/build.gradle.kts
--- a/build.gradle.kts	(revision 2970f435391c92cfe9927fc256b92684b575be7a)
+++ b/build.gradle.kts	(date 1699436218216)
@@ -7,6 +7,7 @@
 
 	alias(libs.plugins.androidApplication) apply false
 	alias(libs.plugins.androidLibrary) apply false
+	alias(libs.plugins.compose) apply false
 }
 
 buildscript {

Similarly, it works no in this reproducer too: https://github.com/dima-avdeev-jb/reproduce-bug-3205 with the attached patch: update_to_kotlin_1_9_20_and_CM_1_5_10.patch

eymar avatar Nov 08 '23 09:11 eymar

That's great news! Thanks a lot.

CLOVIS-AI avatar Nov 08 '23 12:11 CLOVIS-AI

Would like to add that we are seeing this too, on plain Android (not KMP), with Base classes, not interfaces. Classes span modules, with composable method being found at each level

class ActivityInAppModule1: ActivityInAppModule2() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            SomeComposable {
                // ...
            }
        }
    }  
}

class ActivityInAppModule2 : ActivityInLibModule() {
}

class ActivityInLibModule : AppCompatActivity() {

    @Composable
    protected fun SomeComposable(
        modifier: Modifier = Modifier,
        content: @Composable () -> Unit,
    ) {
        Box(
            modifier = modifier,
            content = content,
        )
    }
}

Seeing this on Kotlin 1.9.21, Compose Compiler 1.5.6, and Compose BOM 2023.10.01

I'm not sure if it's related but we also have the Gradle build cache enabled. Clearing the build cache and rebuilding is the only way to get rid of the issue.

DarioAhdoot avatar Dec 21 '23 09:12 DarioAhdoot

Happens occasionally, can't really create a reproducer, for Composables in interfaces again with version 1.6.0-beta01, did not occur for me on alpha.

DatL4g avatar Feb 03 '24 17:02 DatL4g