Skip to content

Commit

Permalink
#864 Fix serialization of Kotlin lambdas (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
theigl committed Apr 6, 2023
1 parent 96259c7 commit 1e29ea7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/com/esotericsoftware/kryo/util/DefaultGenerics.java
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
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() })
}
}

0 comments on commit 1e29ea7

Please sign in to comment.