Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not deserialize kotlin-generated SAM from JVM bytecode in lambda notation #867

Closed
holgerbrandl opened this issue Nov 12, 2021 · 2 comments
Labels

Comments

@holgerbrandl
Copy link

Describe the bug
It fails to serialize a SAM instance created in place using lambda notation. Regular object SAM instances derserialize correctly using the same protocol.

To Reproduce
https://github.com/holgerbrandl/kryo-kotlin-sam/blob/master/src/main/java/KyroSimpleCQ.kt#L53

The line link points to the failing example. I've added a few experiments above that all work fine. I've also added a grade project context to the example for better reproducibility

As it might help to trace down the root cause, I've also added the generated JVM bytecode to the repo under https://github.com/holgerbrandl/kryo-kotlin-sam/tree/master/compiler_output

I'd think that the class/variable names created by the kotlin compiler are legit JVM bytecode, but are different compared to what the java compiler would typically create here.

Environment:

  • OS: Windows10
  • JDK Version: 11
  • Kryo Version: 5.2.0
@theigl
Copy link
Collaborator

theigl commented Nov 12, 2021

You can make this work by using the same approach as for Java Closures:

kryo.register(SerializedLambda::class.java)
kryo.register(ClosureSerializer.Closure::class.java, ClosureSerializer())

This only works for serializable lambdas, so you need to change your interface or cast the lambda accordingly:

fun interface SmthgSAMGeneric<T> : java.io.Serializable {
    fun foo(): (T, T) -> String
}

@holgerbrandl
Copy link
Author

FYI, some more insightful info regarding this issue has been added in https://kotlinlang.slack.com/archives/C7L3JB43G/p1639127887185300?thread_ts=1636705880.135000&cid=C7L3JB43G

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants