diff --git a/src/com/esotericsoftware/kryo/util/DefaultGenerics.java b/src/com/esotericsoftware/kryo/util/DefaultGenerics.java index eeb22735f..e91a851ca 100644 --- a/src/com/esotericsoftware/kryo/util/DefaultGenerics.java +++ b/src/com/esotericsoftware/kryo/util/DefaultGenerics.java @@ -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; diff --git a/test-kotlin/com.esotericsoftware.kryo/LambdaTest.kt b/test-kotlin/com.esotericsoftware.kryo/SerializationTest.kt similarity index 90% rename from test-kotlin/com.esotericsoftware.kryo/LambdaTest.kt rename to test-kotlin/com.esotericsoftware.kryo/SerializationTest.kt index d6f504f31..dbd9bec5f 100644 --- a/test-kotlin/com.esotericsoftware.kryo/LambdaTest.kt +++ b/test-kotlin/com.esotericsoftware.kryo/SerializationTest.kt @@ -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 @@ -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() }) + } }