Skip to content

Commit f6f6570

Browse files
committed
#864 Fix serialization of Kotlin lambdas
1 parent 96259c7 commit f6f6570

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/com/esotericsoftware/kryo/util/DefaultGenerics.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ public Class nextGenericClass () {
9393

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

99100
int startSize = this.argumentsSize;
100101

test-kotlin/com.esotericsoftware.kryo/LambdaTest.kt renamed to test-kotlin/com.esotericsoftware.kryo/SerializationTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ import com.esotericsoftware.kryo.io.Input
44
import com.esotericsoftware.kryo.io.Output
55
import org.junit.jupiter.api.Assertions.assertEquals
66
import org.junit.jupiter.api.Assertions.assertNotSame
7-
import org.junit.jupiter.api.Disabled
87
import org.junit.jupiter.api.Test
98

10-
class LambdaTest {
11-
class Example(private val p: (Long) -> String) {
12-
constructor() : this({ it.toString() })
13-
}
9+
class SerializationTest {
1410

11+
// https://github.com/EsotericSoftware/kryo/issues/864
1512
@Test
16-
@Disabled("Expected to fail")
1713
fun testLambda() {
1814
val kryo = Kryo().apply {
1915
isRegistrationRequired = false
@@ -33,5 +29,9 @@ class LambdaTest {
3329
assertEquals(example::class.java, deserialized::class.java)
3430
assertNotSame(example, deserialized)
3531
}
32+
33+
class Example(private val p: (Long) -> String) {
34+
constructor() : this({ it.toString() })
35+
}
3636
}
3737

0 commit comments

Comments
 (0)