[kpm] serializationUtil.kt: Implement custom ClassLoaderObjectInputStream

Previously used the Gradle implementation, which had an undesirable
fallback for the case of missing classes in the given class loader.

For our tests, we want to ensure that only the specified class loader
is used.
This commit is contained in:
sebastian.sellmair
2022-05-24 10:22:57 +02:00
committed by Space
parent 7eb6288262
commit c9a079f908
@@ -1,6 +1,5 @@
package org.jetbrains.kotlin.gradle.kpm.idea.testFixtures
import org.gradle.internal.io.ClassLoaderObjectInputStream
import java.io.*
/*
@@ -26,3 +25,10 @@ fun ByteArray.deserialize(classLoader: ClassLoader): Any {
val objectInputStream = ClassLoaderObjectInputStream(inputStream, classLoader)
return objectInputStream.use { it.readObject() }
}
class ClassLoaderObjectInputStream(stream: InputStream?, private val classLoader: ClassLoader) : ObjectInputStream(stream) {
@Throws(IOException::class, ClassNotFoundException::class)
override fun resolveClass(desc: ObjectStreamClass): Class<*> {
return Class.forName(desc.name, false, classLoader)
}
}