Describe the bug
Adding serializable annotation to class prevent successful build using the IR backend
To Reproduce
Try to build a project with the following class:
package models.salable
import annotation.audit.Audited
import annotation.audit.NotAudited
import annotation.persistence.Entity
import kotlinx.serialization.Serializable
@kotlin.js.ExperimentalJsExport
@kotlin.js.JsExport
@Serializable
@Open
@NoArgsConstructor
@Audited
@Entity
class Product : Marketable() {
@NotAudited
var stockKeepingUnit: String? = null
}
Gives the following error output :
> Task :compileProductionExecutableKotlinJs FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.3/userguide/command_line_interface.html#sec:command_line_warnings
56 actionable tasks: 9 executed, 47 up-to-date
e: java.lang.IllegalStateException: Class models.salable.Product.Companion with kind: OBJECT
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.exportClass(ExportModelGenerator.kt:143)
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.exportClass(ExportModelGenerator.kt:165)
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.exportDeclaration(ExportModelGenerator.kt:56)
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.generateExport(ExportModelGenerator.kt:32)
at org.jetbrains.kotlin.ir.backend.js.export.ExportModelGenerator.generateExport(ExportModelGenerator.kt:45)
at org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer.generateModule(IrModuleToJsTransformer.kt:46)
at org.jetbrains.kotlin.ir.backend.js.CompilerKt.compile(compiler.kt:104)
at org.jetbrains.kotlin.ir.backend.js.CompilerKt.compile$default(compiler.kt:48)
at org.jetbrains.kotlin.cli.js.K2JsIrCompiler.doExecute(K2JsIrCompiler.kt:221)
at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:181)
at org.jetbrains.kotlin.cli.js.K2JSCompiler.doExecute(K2JSCompiler.java:74)
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.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1549)
at jdk.internal.reflect.GeneratedMethodAccessor104.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:832)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileProductionExecutableKotlinJs'.
> Internal compiler error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6s
Removing the @Serializable fix the build, but this annotation is needed for the serialization lib to work
Expected behavior
Successfully built
Environment
1.4.0-rcorg.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.8-1.4.0-rcJVM, JS, Android6.5.1JRE 14EDIT: Event if the error mention (...) .Companion with kind: OBJECT, the Product class does not have any companion object (even in its parent classes)
Same problem here. I can't add @JsExport (now required if you want to generate readable JS) to classes I want to include in my API because it fails the build. Compilation with the IR backend works without @JsExport.
In addition, when trying to use the LEGACY backend as a workaround for now, I get Uncaught SerializationException: Serializer for class '...' is not found exceptions. On the IR backend (without @JsExport) all my JVM and JS unit tests pass.
I noticed the version 1.4.0 of this library is out. Is the serialization now compatible with the JS IR backend ?
@daweedm kotlinx.serialization 1.0.0-RC is compatible with 1.4.0 Kotlin/JS IR compiler. However, due to this bug, serializable declarations can't be @JsExported
Most helpful comment
https://youtrack.jetbrains.com/issue/KT-39740