Describe the bug
When trying to integrate kotlinx.serialization, unable to compile.
e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation
File being compiled: /home/malachid/work/poc/src/main/kotlin/TestData.kt
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50)
at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException(CodegenUtil.kt:239)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm(JvmBackendFacade.kt:142)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm$default(JvmBackendFacade.kt:108)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFiles(JvmBackendFacade.kt:95)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.generateModule(JvmIrCodegenFactory.kt:40)
at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:35)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.generate(KotlinToJVMBytecodeCompiler.kt:616)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:203)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:164)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:51)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:86)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:346)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:102)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:240)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:39)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:81)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:93)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:601)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:93)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1633)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Exception while generating code for:
CONSTRUCTOR visibility:public <> (seen1:kotlin.Int, thing:kotlin.Int?, serializationConstructorMarker:kotlinx.serialization.internal.SerializationConstructorMarker?) returnType:<root>.TestData
annotations:
Deprecated(message = 'This synthesized declaration should not be used directly', replaceWith = ReplaceWith(expression = '', imports = []), level = GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:HIDDEN' type=kotlin.DeprecationLevel)
VALUE_PARAMETER name:seen1 index:0 type:kotlin.Int
VALUE_PARAMETER name:thing index:1 type:kotlin.Int?
VALUE_PARAMETER name:serializationConstructorMarker index:2 type:kotlinx.serialization.internal.SerializationConstructorMarker?
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generateMethodNode(ClassCodegen.kt:268)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generateMethod(ClassCodegen.kt:285)
at org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen.generate(ClassCodegen.kt:123)
at org.jetbrains.kotlin.backend.jvm.JvmBackendFacade.doGenerateFilesInternal$backend_jvm(JvmBackendFacade.kt:139)
... 37 more
Caused by: java.lang.NullPointerException
at org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen.generate(ExpressionCodegen.kt:199)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.doGenerate(FunctionCodegen.kt:105)
at org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:48)
... 41 more
FAILURE: Build failed with an exception.
To Reproduce
kotlin("plugin.serialization") version "1.4.10"implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")src/main/kotlin:import kotlinx.serialization.*
@Serializable
data class TestData(var thing: Int? = null)
(I have tested w/ and w/o the default value; with var and val)
Expected behavior
App should compile.
As a side note, you have to include json support - even if that isn't the intended target; or the IDE can't resolve @Serializable.
Environment
kotlinx.serialization currently is not fully compatible with Jetpack Compose
I've currently encountered the same issue for a sealed class's child which uses the @Serializable annotation: Stacktrace Gist
The implementation was working before when I was purely using Kotlin Platform Mobile (along with Jetpack Compose for Android), but it started failing once I introduced Jetbrains Compose for Desktop (along with its modifications for :common's build.gradle.kts file).
Is there a timeline on when compatibility for these two might be introduced?
i've got the same error, anyone has a way out of this. Kinda Brings me down things were working well. :/
I put my serializable classes into a gradle subproject with the serialization plugin and no compose plugin, and then had the subproject with the compose plugin and no serialization plugin depend on that. Hope that helps.
Most helpful comment
I've currently encountered the same issue for a
sealed class's child which uses the@Serializableannotation: Stacktrace GistThe implementation was working before when I was purely using Kotlin Platform Mobile (along with Jetpack Compose for Android), but it started failing once I introduced Jetbrains Compose for Desktop (along with its modifications for
:common'sbuild.gradle.ktsfile).Is there a timeline on when compatibility for these two might be introduced?