Skip to content

Commit

Permalink
#864 Fix serialization of Kotlin lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
theigl committed Apr 5, 2023
1 parent 96259c7 commit f6f6570
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
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() })
}
}

0 comments on commit f6f6570

Please sign in to comment.