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

#864 Fix serialization of Kotlin lambdas #951

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/com/esotericsoftware/kryo/util/DefaultGenerics.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ public Class nextGenericClass () {

@Override
public int pushTypeVariables (GenericsHierarchy hierarchy, GenericType[] args) {
// Do not store type variables if hierarchy is empty or we do not have arguments for all root parameters.
if (hierarchy.total == 0 || hierarchy.rootTotal > args.length) return 0;
// Do not store type variables if hierarchy is empty, or we do not have arguments for all root parameters, or we have more
// arguments than the hierarchy has parameters.
if (hierarchy.total == 0 || hierarchy.rootTotal > args.length || args.length > hierarchy.counts.length) return 0;

int startSize = this.argumentsSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotSame
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

class LambdaTest {
class Example(private val p: (Long) -> String) {
constructor() : this({ it.toString() })
}
class SerializationTest {

// https://github.com/EsotericSoftware/kryo/issues/864
@Test
@Disabled("Expected to fail")
fun testLambda() {
val kryo = Kryo().apply {
isRegistrationRequired = false
Expand All @@ -33,5 +29,9 @@ class LambdaTest {
assertEquals(example::class.java, deserialized::class.java)
assertNotSame(example, deserialized)
}

class Example(private val p: (Long) -> String) {
constructor() : this({ it.toString() })
}
}