CORDA-2871: Modify sandbox tasks to implement both java.Function and sandbox.Function (#62)

* Modify sandbox tasks to implement both java.Function and sandbox.Function.
* Make TaskExecutors implement BiFunction to make them composable.
* Create ImportTask to wrap a java.Function inside a sandbox.Function.
* Add createExecutor() and createRawExecutor() APIs to SandboxClassLoader.
* Update serialization to use SandboxClassLoader.toSandboxClass().
* Remove a layer of lambdas from the serialisation code.
* Update SandboxExecutor and SandboxRawExecutor.
* Rename Executor to TaskFactory.
* Rename dangling executor -> taskFactory.
This commit is contained in:
Chris Rankin 2019-09-10 10:55:55 +01:00 committed by GitHub
parent 7a6c18156c
commit 062acf89be
75 changed files with 500 additions and 787 deletions

View File

@ -12,37 +12,36 @@ import net.corda.serialization.internal.amqp.*
import java.math.BigDecimal
import java.math.BigInteger
import java.util.*
import java.util.function.BiFunction
import java.util.function.Function
class AMQPSerializationScheme(
private val classLoader: SandboxClassLoader,
private val sandboxBasicInput: Function<in Any?, out Any?>,
private val executor: BiFunction<in Any, in Any?, out Any?>,
private val taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
private val serializerFactoryFactory: SerializerFactoryFactory
) : SerializationScheme {
private fun getSerializerFactory(context: SerializationContext): SerializerFactory {
return serializerFactoryFactory.make(context).apply {
register(SandboxBitSetSerializer(classLoader, executor, this))
register(SandboxCertPathSerializer(classLoader, executor, this))
register(SandboxDurationSerializer(classLoader, executor, this))
register(SandboxEnumSetSerializer(classLoader, executor, this))
register(SandboxInputStreamSerializer(classLoader, executor))
register(SandboxInstantSerializer(classLoader, executor, this))
register(SandboxLocalDateSerializer(classLoader, executor, this))
register(SandboxLocalDateTimeSerializer(classLoader, executor, this))
register(SandboxLocalTimeSerializer(classLoader, executor, this))
register(SandboxMonthDaySerializer(classLoader, executor, this))
register(SandboxOffsetDateTimeSerializer(classLoader, executor, this))
register(SandboxOffsetTimeSerializer(classLoader, executor, this))
register(SandboxPeriodSerializer(classLoader, executor, this))
register(SandboxYearMonthSerializer(classLoader, executor, this))
register(SandboxYearSerializer(classLoader, executor, this))
register(SandboxZonedDateTimeSerializer(classLoader, executor, this))
register(SandboxZoneIdSerializer(classLoader, executor, this))
register(SandboxOpaqueBytesSubSequenceSerializer(classLoader, executor, this))
register(SandboxOptionalSerializer(classLoader, executor, this))
register(SandboxBitSetSerializer(classLoader, taskFactory, this))
register(SandboxCertPathSerializer(classLoader, taskFactory, this))
register(SandboxDurationSerializer(classLoader, taskFactory, this))
register(SandboxEnumSetSerializer(classLoader, taskFactory, this))
register(SandboxInputStreamSerializer(classLoader, taskFactory))
register(SandboxInstantSerializer(classLoader, taskFactory, this))
register(SandboxLocalDateSerializer(classLoader, taskFactory, this))
register(SandboxLocalDateTimeSerializer(classLoader, taskFactory, this))
register(SandboxLocalTimeSerializer(classLoader, taskFactory, this))
register(SandboxMonthDaySerializer(classLoader, taskFactory, this))
register(SandboxOffsetDateTimeSerializer(classLoader, taskFactory, this))
register(SandboxOffsetTimeSerializer(classLoader, taskFactory, this))
register(SandboxPeriodSerializer(classLoader, taskFactory, this))
register(SandboxYearMonthSerializer(classLoader, taskFactory, this))
register(SandboxYearSerializer(classLoader, taskFactory, this))
register(SandboxZonedDateTimeSerializer(classLoader, taskFactory, this))
register(SandboxZoneIdSerializer(classLoader, taskFactory, this))
register(SandboxOpaqueBytesSubSequenceSerializer(classLoader, taskFactory, this))
register(SandboxOptionalSerializer(classLoader, taskFactory, this))
register(SandboxPrimitiveSerializer(UUID::class.java, classLoader, sandboxBasicInput))
register(SandboxPrimitiveSerializer(String::class.java, classLoader, sandboxBasicInput))
register(SandboxPrimitiveSerializer(Byte::class.javaObjectType, classLoader, sandboxBasicInput))
@ -54,24 +53,24 @@ class AMQPSerializationScheme(
register(SandboxPrimitiveSerializer(Boolean::class.javaObjectType, classLoader, sandboxBasicInput))
register(SandboxPrimitiveSerializer(Date::class.javaObjectType, classLoader, sandboxBasicInput))
register(SandboxCharacterSerializer(classLoader, sandboxBasicInput))
register(SandboxCollectionSerializer(classLoader, executor, this))
register(SandboxMapSerializer(classLoader, executor, this))
register(SandboxEnumSerializer(classLoader, executor, this))
register(SandboxPublicKeySerializer(classLoader, executor))
register(SandboxToStringSerializer(BigDecimal::class.java, classLoader, executor, sandboxBasicInput))
register(SandboxToStringSerializer(BigInteger::class.java, classLoader, executor, sandboxBasicInput))
register(SandboxToStringSerializer(StringBuffer::class.java, classLoader, executor, sandboxBasicInput))
register(SandboxCurrencySerializer(classLoader, executor, sandboxBasicInput))
register(SandboxX509CertificateSerializer(classLoader, executor))
register(SandboxX509CRLSerializer(classLoader, executor))
register(SandboxUnsignedLongSerializer(classLoader, executor))
register(SandboxUnsignedIntegerSerializer(classLoader, executor))
register(SandboxUnsignedShortSerializer(classLoader, executor))
register(SandboxUnsignedByteSerializer(classLoader, executor))
register(SandboxDecimal128Serializer(classLoader, executor))
register(SandboxDecimal64Serializer(classLoader, executor))
register(SandboxDecimal32Serializer(classLoader, executor))
register(SandboxSymbolSerializer(classLoader, executor, sandboxBasicInput))
register(SandboxCollectionSerializer(classLoader, taskFactory, this))
register(SandboxMapSerializer(classLoader, taskFactory, this))
register(SandboxEnumSerializer(classLoader, taskFactory, this))
register(SandboxPublicKeySerializer(classLoader, taskFactory))
register(SandboxToStringSerializer(BigDecimal::class.java, classLoader, taskFactory, sandboxBasicInput))
register(SandboxToStringSerializer(BigInteger::class.java, classLoader, taskFactory, sandboxBasicInput))
register(SandboxToStringSerializer(StringBuffer::class.java, classLoader, taskFactory, sandboxBasicInput))
register(SandboxCurrencySerializer(classLoader, taskFactory, sandboxBasicInput))
register(SandboxX509CertificateSerializer(classLoader, taskFactory))
register(SandboxX509CRLSerializer(classLoader, taskFactory))
register(SandboxUnsignedLongSerializer(classLoader, taskFactory))
register(SandboxUnsignedIntegerSerializer(classLoader, taskFactory))
register(SandboxUnsignedShortSerializer(classLoader, taskFactory))
register(SandboxUnsignedByteSerializer(classLoader, taskFactory))
register(SandboxDecimal128Serializer(classLoader, taskFactory))
register(SandboxDecimal64Serializer(classLoader, taskFactory))
register(SandboxDecimal32Serializer(classLoader, taskFactory))
register(SandboxSymbolSerializer(classLoader, taskFactory, sandboxBasicInput))
}
}

View File

@ -7,22 +7,19 @@ import net.corda.core.serialization.SerializationFactory
import net.corda.core.serialization.SerializedBytes
import net.corda.core.serialization.internal.SerializationEnvironment
import net.corda.core.utilities.ByteSequence
import net.corda.djvm.execution.SandboxRuntimeException
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.serializers.PrimitiveSerializer
import net.corda.djvm.source.ClassSource
import net.corda.serialization.internal.GlobalTransientClassWhiteList
import net.corda.serialization.internal.SerializationContextImpl
import net.corda.serialization.internal.SerializationFactoryImpl
import net.corda.serialization.internal.amqp.AMQPSerializer
import net.corda.serialization.internal.amqp.amqpMagic
import java.lang.reflect.InvocationTargetException
import java.util.function.BiFunction
import java.util.function.Function
fun SandboxClassLoader.loadClassForSandbox(clazz: Class<*>): Class<Any> {
@Suppress("NOTHING_TO_INLINE")
inline fun SandboxClassLoader.toSandboxAnyClass(clazz: Class<*>): Class<Any> {
@Suppress("unchecked_cast")
return loadClassForSandbox(ClassSource.fromClassName(clazz.name)) as Class<Any>
return toSandboxClass(clazz) as Class<Any>
}
fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): SerializationEnvironment {
@ -37,21 +34,7 @@ fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): Serializatio
encoding = null
)
val taskClass = classLoader.loadClass("sandbox.RawTask")
val taskApply = taskClass.getDeclaredMethod("apply", Any::class.java)
val taskConstructor = taskClass.getDeclaredConstructor(classLoader.loadClassForSandbox(Function::class.java))
val executor: BiFunction<in Any, in Any?, out Any?> = BiFunction { userTask, arg ->
try {
taskApply(taskConstructor.newInstance(userTask), arg)
} catch (ex: InvocationTargetException) {
val target = ex.targetException
throw when (target) {
is RuntimeException, is Error -> target
else -> SandboxRuntimeException(target.message, target)
}
}
}
val taskFactory = classLoader.createRawTaskFactory()
val sandboxBasicInput = classLoader.createBasicInput()
val primitiveSerializerFactory: Function<Class<*>, AMQPSerializer<Any>> = Function { clazz ->
@ -62,7 +45,7 @@ fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): Serializatio
registerScheme(AMQPSerializationScheme(
classLoader = classLoader,
sandboxBasicInput = sandboxBasicInput,
executor = executor,
taskFactory = taskFactory,
serializerFactoryFactory = SandboxSerializerFactoryFactory(primitiveSerializerFactory)
))
}
@ -70,7 +53,7 @@ fun createSandboxSerializationEnv(classLoader: SandboxClassLoader): Serializatio
}
inline fun <reified T : Any> SerializedBytes<T>.deserializeFor(classLoader: SandboxClassLoader): Any {
val clazz = classLoader.loadClassForSandbox(T::class.java)
val clazz = classLoader.toSandboxClass(T::class.java)
return deserializeTo(clazz, classLoader)
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.BitSetDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.BitSetSerializer.BitSetProxy
import java.util.*
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxBitSetSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(BitSet::class.java),
proxyClass = classLoader.loadClassForSandbox(BitSetProxy::class.java),
clazz = classLoader.toSandboxAnyClass(BitSet::class.java),
proxyClass = classLoader.toSandboxAnyClass(BitSetProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(BitSetDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, BitSetDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(BitSet::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.CertPathDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.CertPathSerializer.CertPathProxy
import java.security.cert.CertPath
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxCertPathSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(CertPath::class.java),
proxyClass = classLoader.loadClassForSandbox(CertPathProxy::class.java),
clazz = classLoader.toSandboxAnyClass(CertPath::class.java),
proxyClass = classLoader.toSandboxAnyClass(CertPathProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(CertPathDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, CertPathDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(CertPath::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,7 +2,7 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
@ -11,7 +11,7 @@ import java.util.function.Function
class SandboxCharacterSerializer(
classLoader: SandboxClassLoader,
private val basicInput: Function<in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(Char::class.javaObjectType)) {
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(Char::class.javaObjectType)) {
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -1,27 +1,25 @@
package net.corda.djvm.serialization.serializers
import net.corda.djvm.execution.SandboxRuntimeException
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.ClassDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.AMQPNotSerializableException
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.ClassSerializer.ClassProxy
import java.util.function.BiFunction
import java.util.function.Function
@Suppress("unchecked_cast")
class SandboxClassSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = Class::class.java as Class<Any>,
proxyClass = classLoader.loadClassForSandbox(ClassProxy::class.java),
proxyClass = classLoader.toSandboxAnyClass(ClassProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(ClassDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, ClassDeserializer::class.java)
private val nameOf: Function<Any, String>
init {
@ -35,13 +33,8 @@ class SandboxClassSerializer(
override fun fromProxy(proxy: Any): Any {
return try {
executor.apply(task, proxy)!!
} catch (e: SandboxRuntimeException) {
val cause = e.cause ?: throw e
if (cause !is ClassNotFoundException) {
throw cause
}
task.apply(proxy)!!
} catch (e: ClassNotFoundException) {
val className = nameOf.apply(proxy)
throw AMQPNotSerializableException(type,
"Could not instantiate $className - not on the classpath",

View File

@ -4,7 +4,7 @@ import net.corda.core.serialization.SerializationContext
import net.corda.core.utilities.NonEmptySet
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.CreateCollection
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import net.corda.serialization.internal.model.LocalTypeInformation
import net.corda.serialization.internal.model.TypeIdentifier
@ -13,27 +13,21 @@ import org.apache.qpid.proton.codec.Data
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import java.util.*
import java.util.function.BiFunction
import java.util.function.Function
class SandboxCollectionSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
private val localFactory: LocalSerializerFactory
) : CustomSerializer.Implements<Any>(clazz = classLoader.loadClassForSandbox(Collection::class.java)) {
) : CustomSerializer.Implements<Any>(clazz = classLoader.toSandboxAnyClass(Collection::class.java)) {
@Suppress("unchecked_cast")
private val creator: Function<Array<Any>, out Any?>
init {
val createTask = classLoader.loadClassForSandbox(CreateCollection::class.java).newInstance()
creator = Function { inputs ->
executor.apply(createTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, CreateCollection::class.java) as Function<Array<Any>, out Any?>
private val unsupportedTypes: Set<Class<Any>> = listOf(
EnumSet::class.java
).map {
classLoader.loadClassForSandbox(it)
classLoader.toSandboxAnyClass(it)
}.toSet()
// The order matters here - the first match should be the most specific one.
@ -46,7 +40,7 @@ class SandboxCollectionSerializer(
Set::class.java,
Collection::class.java
).associateBy {
classLoader.loadClassForSandbox(it)
classLoader.toSandboxAnyClass(it)
}
private fun getBestMatchFor(type: Class<Any>): Map.Entry<Class<Any>, Class<out Collection<*>>>

View File

@ -3,29 +3,27 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.CreateCurrency
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.*
import java.util.function.BiFunction
import java.util.Collections.singleton
import java.util.function.Function
class SandboxCurrencySerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
basicInput: Function<in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(Currency::class.java)) {
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(Currency::class.java)) {
private val creator: Function<Any?, Any?>
init {
val createTask = classLoader.loadClassForSandbox(CreateCurrency::class.java).newInstance()
creator = basicInput.andThen { input ->
executor.apply(createTask, input)
}
val createTask = classLoader.createTaskFor(taskFactory, CreateCurrency::class.java)
creator = basicInput.andThen(createTask)
}
override val deserializationAliases: Set<Class<*>> = Collections.singleton(Currency::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(Currency::class.java)
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.Decimal128Deserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.amqp.Decimal128
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.function.BiFunction
import java.util.function.Function
class SandboxDecimal128Serializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(Decimal128::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(Decimal128::class.java)) {
@Suppress("unchecked_cast")
private val transformer: Function<LongArray, out Any?>
init {
val transformTask = classLoader.loadClassForSandbox(Decimal128Deserializer::class.java).newInstance()
transformer = Function { inputs ->
executor.apply(transformTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, Decimal128Deserializer::class.java) as Function<LongArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.Decimal32Deserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.amqp.Decimal32
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.function.BiFunction
import java.util.function.Function
class SandboxDecimal32Serializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(Decimal32::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(Decimal32::class.java)) {
@Suppress("unchecked_cast")
private val transformer: Function<IntArray, out Any?>
init {
val transformTask = classLoader.loadClassForSandbox(Decimal32Deserializer::class.java).newInstance()
transformer = Function { inputs ->
executor.apply(transformTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, Decimal32Deserializer::class.java) as Function<IntArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.Decimal64Deserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.amqp.Decimal64
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.function.BiFunction
import java.util.function.Function
class SandboxDecimal64Serializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(Decimal64::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(Decimal64::class.java)) {
@Suppress("unchecked_cast")
private val transformer: Function<LongArray, out Any?>
init {
val transformTask = classLoader.loadClassForSandbox(Decimal64Deserializer::class.java).newInstance()
transformer = Function { inputs ->
executor.apply(transformTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, Decimal64Deserializer::class.java) as Function<LongArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.DurationDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.DurationSerializer.DurationProxy
import java.time.Duration
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxDurationSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(Duration::class.java),
proxyClass = classLoader.loadClassForSandbox(DurationProxy::class.java),
clazz = classLoader.toSandboxAnyClass(Duration::class.java),
proxyClass = classLoader.toSandboxAnyClass(DurationProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(DurationDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, DurationDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(Duration::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -3,7 +3,7 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.DescribeEnum
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import net.corda.serialization.internal.model.EnumTransforms
import net.corda.serialization.internal.model.LocalTypeInformation
@ -11,23 +11,16 @@ import net.corda.serialization.internal.model.TypeIdentifier
import org.apache.qpid.proton.amqp.Symbol
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.function.BiFunction
import java.util.function.Function
class SandboxEnumSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
private val localFactory: LocalSerializerFactory
) : CustomSerializer.Implements<Any>(clazz = classLoader.loadClassForSandbox(Enum::class.java)) {
) : CustomSerializer.Implements<Any>(clazz = classLoader.toSandboxAnyClass(Enum::class.java)) {
@Suppress("unchecked_cast")
private val describer: Function<Class<*>, Array<Any>>
init {
val describeTask = classLoader.loadClassForSandbox(DescribeEnum::class.java).newInstance()
describer = Function { inputs ->
@Suppress("unchecked_cast")
executor.apply(describeTask, inputs) as Array<Any>
}
}
= classLoader.createTaskFor(taskFactory, DescribeEnum::class.java) as Function<Class<*>, Array<Any>>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -2,27 +2,27 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.EnumSetDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.EnumSetSerializer.EnumSetProxy
import java.util.*
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxEnumSetSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(EnumSet::class.java),
proxyClass = classLoader.loadClassForSandbox(EnumSetProxy::class.java),
clazz = classLoader.toSandboxAnyClass(EnumSet::class.java),
proxyClass = classLoader.toSandboxAnyClass(EnumSetProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(EnumSetDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, EnumSetDeserializer::class.java)
override val additionalSerializers: Set<CustomSerializer<out Any>> = singleton(
SandboxClassSerializer(classLoader, executor, factory)
SandboxClassSerializer(classLoader, taskFactory, factory)
)
override val deserializationAliases: Set<Class<*>> = singleton(EnumSet::class.java)
@ -30,6 +30,6 @@ class SandboxEnumSetSerializer(
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -3,27 +3,21 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.InputStreamDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.codec.Data
import java.io.InputStream
import java.lang.reflect.Type
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxInputStreamSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Implements<Any>(classLoader.loadClassForSandbox(InputStream::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Implements<Any>(classLoader.toSandboxAnyClass(InputStream::class.java)) {
@Suppress("unchecked_cast")
private val decoder: Function<ByteArray, out Any?>
init {
val decodeTask = classLoader.loadClassForSandbox(InputStreamDeserializer::class.java).newInstance()
decoder = Function { inputs ->
executor.apply(decodeTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, InputStreamDeserializer::class.java) as Function<ByteArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.InstantDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.InstantSerializer.InstantProxy
import java.time.Instant
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxInstantSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(Instant::class.java),
proxyClass = classLoader.loadClassForSandbox(InstantProxy::class.java),
clazz = classLoader.toSandboxAnyClass(Instant::class.java),
proxyClass = classLoader.toSandboxAnyClass(InstantProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(InstantDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, InstantDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(Instant::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.LocalDateDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.LocalDateSerializer.LocalDateProxy
import java.time.LocalDate
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxLocalDateSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(LocalDate::class.java),
proxyClass = classLoader.loadClassForSandbox(LocalDateProxy::class.java),
clazz = classLoader.toSandboxAnyClass(LocalDate::class.java),
proxyClass = classLoader.toSandboxAnyClass(LocalDateProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(LocalDateDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, LocalDateDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(LocalDate::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.LocalDateTimeDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.LocalDateTimeSerializer.LocalDateTimeProxy
import java.time.LocalDateTime
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxLocalDateTimeSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(LocalDateTime::class.java),
proxyClass = classLoader.loadClassForSandbox(LocalDateTimeProxy::class.java),
clazz = classLoader.toSandboxAnyClass(LocalDateTime::class.java),
proxyClass = classLoader.toSandboxAnyClass(LocalDateTimeProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(LocalDateTimeDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, LocalDateTimeDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(LocalDateTime::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.LocalTimeDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.LocalTimeSerializer.LocalTimeProxy
import java.time.LocalTime
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxLocalTimeSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(LocalTime::class.java),
proxyClass = classLoader.loadClassForSandbox(LocalTimeProxy::class.java),
clazz = classLoader.toSandboxAnyClass(LocalTime::class.java),
proxyClass = classLoader.toSandboxAnyClass(LocalTimeProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(LocalTimeDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, LocalTimeDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(LocalTime::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -3,7 +3,7 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.CreateMap
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import net.corda.serialization.internal.model.LocalTypeInformation
import net.corda.serialization.internal.model.TypeIdentifier
@ -12,22 +12,16 @@ import org.apache.qpid.proton.codec.Data
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import java.util.*
import java.util.function.BiFunction
import java.util.function.Function
class SandboxMapSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
private val localFactory: LocalSerializerFactory
) : CustomSerializer.Implements<Any>(clazz = classLoader.loadClassForSandbox(Map::class.java)) {
) : CustomSerializer.Implements<Any>(clazz = classLoader.toSandboxAnyClass(Map::class.java)) {
@Suppress("unchecked_cast")
private val creator: Function<Array<Any>, out Any?>
init {
val createTask = classLoader.loadClassForSandbox(CreateMap::class.java).newInstance()
creator = Function { inputs ->
executor.apply(createTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, CreateMap::class.java) as Function<Array<Any>, out Any?>
// The order matters here - the first match should be the most specific one.
// Kotlin preserves the ordering for us by associating into a LinkedHashMap.
@ -39,7 +33,7 @@ class SandboxMapSerializer(
EnumMap::class.java,
Map::class.java
).associateBy {
classLoader.loadClassForSandbox(it)
classLoader.toSandboxAnyClass(it)
}
private fun getBestMatchFor(type: Class<Any>): Map.Entry<Class<Any>, Class<out Map<*, *>>>

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.MonthDayDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.MonthDaySerializer.MonthDayProxy
import java.time.MonthDay
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxMonthDaySerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(MonthDay::class.java),
proxyClass = classLoader.loadClassForSandbox(MonthDayProxy::class.java),
clazz = classLoader.toSandboxAnyClass(MonthDay::class.java),
proxyClass = classLoader.toSandboxAnyClass(MonthDayProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(MonthDayDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, MonthDayDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(MonthDay::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.OffsetDateTimeDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.OffsetDateTimeSerializer.OffsetDateTimeProxy
import java.time.OffsetDateTime
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxOffsetDateTimeSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(OffsetDateTime::class.java),
proxyClass = classLoader.loadClassForSandbox(OffsetDateTimeProxy::class.java),
clazz = classLoader.toSandboxAnyClass(OffsetDateTime::class.java),
proxyClass = classLoader.toSandboxAnyClass(OffsetDateTimeProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(OffsetDateTimeDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, OffsetDateTimeDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(OffsetDateTime::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.OffsetTimeDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.OffsetTimeSerializer.OffsetTimeProxy
import java.time.OffsetTime
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxOffsetTimeSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(OffsetTime::class.java),
proxyClass = classLoader.loadClassForSandbox(OffsetTimeProxy::class.java),
clazz = classLoader.toSandboxAnyClass(OffsetTime::class.java),
proxyClass = classLoader.toSandboxAnyClass(OffsetTimeProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(OffsetTimeDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, OffsetTimeDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(OffsetTime::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -4,28 +4,28 @@ import net.corda.core.utilities.OpaqueBytes
import net.corda.core.utilities.OpaqueBytesSubSequence
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.OpaqueBytesSubSequenceDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxOpaqueBytesSubSequenceSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(OpaqueBytesSubSequence::class.java),
proxyClass = classLoader.loadClassForSandbox(OpaqueBytes::class.java),
clazz = classLoader.toSandboxAnyClass(OpaqueBytesSubSequence::class.java),
proxyClass = classLoader.toSandboxAnyClass(OpaqueBytes::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(OpaqueBytesSubSequenceDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, OpaqueBytesSubSequenceDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(OpaqueBytesSubSequence::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.OptionalDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.OptionalSerializer.OptionalProxy
import java.util.*
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxOptionalSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(Optional::class.java),
proxyClass = classLoader.loadClassForSandbox(OptionalProxy::class.java),
clazz = classLoader.toSandboxAnyClass(Optional::class.java),
proxyClass = classLoader.toSandboxAnyClass(OptionalProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(OptionalDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, OptionalDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(Optional::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.PeriodDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.PeriodSerializer.PeriodProxy
import java.time.Period
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxPeriodSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(Period::class.java),
proxyClass = classLoader.loadClassForSandbox(PeriodProxy::class.java),
clazz = classLoader.toSandboxAnyClass(Period::class.java),
proxyClass = classLoader.toSandboxAnyClass(PeriodProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(PeriodDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, PeriodDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(Period::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,7 +2,7 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
@ -12,7 +12,7 @@ class SandboxPrimitiveSerializer(
clazz: Class<*>,
classLoader: SandboxClassLoader,
private val basicInput: Function<in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(clazz)) {
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(clazz)) {
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,27 +3,21 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.PublicKeyDecoder
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.security.PublicKey
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxPublicKeySerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Implements<Any>(classLoader.loadClassForSandbox(PublicKey::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Implements<Any>(classLoader.toSandboxAnyClass(PublicKey::class.java)) {
@Suppress("unchecked_cast")
private val decoder: Function<ByteArray, out Any?>
init {
val decodeTask = classLoader.loadClassForSandbox(PublicKeyDecoder::class.java).newInstance()
decoder = Function { inputs ->
executor.apply(decodeTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, PublicKeyDecoder::class.java) as Function<ByteArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,27 +3,24 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.SymbolDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.amqp.Symbol
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.function.BiFunction
import java.util.function.Function
class SandboxSymbolSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
basicInput: Function<in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(Symbol::class.java)) {
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(Symbol::class.java)) {
private val transformer: Function<String, out Any?>
init {
val transformTask = classLoader.loadClassForSandbox(SymbolDeserializer::class.java).newInstance()
val transformTask = classLoader.createTaskFor(taskFactory, SymbolDeserializer::class.java)
@Suppress("unchecked_cast")
transformer = basicInput.andThen { input ->
executor.apply(transformTask, input)
} as Function<String, Any?>
transformer = basicInput.andThen(transformTask) as Function<String, Any?>
}
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,31 +3,28 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.CreateFromString
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Constructor
import java.lang.reflect.Type
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxToStringSerializer(
unsafeClass: Class<*>,
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
basicInput: Function<in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(unsafeClass)) {
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(unsafeClass)) {
private val creator: Function<Any?, Any?>
init {
val stringClass = classLoader.loadClass("sandbox.java.lang.String")
val createTask = classLoader.loadClassForSandbox(CreateFromString::class.java)
val createTask = classLoader.toSandboxClass(CreateFromString::class.java)
.getConstructor(Constructor::class.java)
.newInstance(clazz.getConstructor(stringClass))
creator = basicInput.andThen { input ->
executor.apply(createTask, input)
}
creator = basicInput.andThen(taskFactory.apply(createTask))
}
override val deserializationAliases: Set<Class<*>> = singleton(unsafeClass)

View File

@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.UnsignedByteDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.amqp.UnsignedByte
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.function.BiFunction
import java.util.function.Function
class SandboxUnsignedByteSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(UnsignedByte::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(UnsignedByte::class.java)) {
@Suppress("unchecked_cast")
private val transformer: Function<ByteArray, out Any?>
init {
val transformTask = classLoader.loadClassForSandbox(UnsignedByteDeserializer::class.java).newInstance()
transformer = Function { inputs ->
executor.apply(transformTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, UnsignedByteDeserializer::class.java) as Function<ByteArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.UnsignedIntegerDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.amqp.UnsignedInteger
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.function.BiFunction
import java.util.function.Function
class SandboxUnsignedIntegerSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(UnsignedInteger::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(UnsignedInteger::class.java)) {
@Suppress("unchecked_cast")
private val transformer: Function<IntArray, out Any?>
init {
val transformTask = classLoader.loadClassForSandbox(UnsignedIntegerDeserializer::class.java).newInstance()
transformer = Function { inputs ->
executor.apply(transformTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, UnsignedIntegerDeserializer::class.java) as Function<IntArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,27 +3,20 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.UnsignedLongDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.amqp.UnsignedLong
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxUnsignedLongSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(UnsignedLong::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(UnsignedLong::class.java)) {
@Suppress("unchecked_cast")
private val transformer: Function<LongArray, out Any?>
init {
val transformTask = classLoader.loadClassForSandbox(UnsignedLongDeserializer::class.java).newInstance()
transformer = Function { inputs ->
executor.apply(transformTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, UnsignedLongDeserializer::class.java) as Function<LongArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,26 +3,20 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.UnsignedShortDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.amqp.UnsignedShort
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.util.function.BiFunction
import java.util.function.Function
class SandboxUnsignedShortSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Is<Any>(classLoader.loadClassForSandbox(UnsignedShort::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Is<Any>(classLoader.toSandboxAnyClass(UnsignedShort::class.java)) {
@Suppress("unchecked_cast")
private val transformer: Function<ShortArray, out Any?>
init {
val transformTask = classLoader.loadClassForSandbox(UnsignedShortDeserializer::class.java).newInstance()
transformer = Function { inputs ->
executor.apply(transformTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, UnsignedShortDeserializer::class.java) as Function<ShortArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,27 +3,21 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.X509CRLDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.security.cert.X509CRL
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxX509CRLSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Implements<Any>(classLoader.loadClassForSandbox(X509CRL::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Implements<Any>(classLoader.toSandboxAnyClass(X509CRL::class.java)) {
@Suppress("unchecked_cast")
private val generator: Function<ByteArray, out Any?>
init {
val generateTask = classLoader.loadClassForSandbox(X509CRLDeserializer::class.java).newInstance()
generator = Function { inputs ->
executor.apply(generateTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, X509CRLDeserializer::class.java) as Function<ByteArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -3,27 +3,21 @@ package net.corda.djvm.serialization.serializers
import net.corda.core.serialization.SerializationContext
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.X509CertificateDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.*
import org.apache.qpid.proton.codec.Data
import java.lang.reflect.Type
import java.security.cert.X509Certificate
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxX509CertificateSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>
) : CustomSerializer.Implements<Any>(classLoader.loadClassForSandbox(X509Certificate::class.java)) {
taskFactory: Function<in Any, out Function<in Any?, out Any?>>
) : CustomSerializer.Implements<Any>(classLoader.toSandboxAnyClass(X509Certificate::class.java)) {
@Suppress("unchecked_cast")
private val generator: Function<ByteArray, out Any?>
init {
val generateTask = classLoader.loadClassForSandbox(X509CertificateDeserializer::class.java).newInstance()
generator = Function { inputs ->
executor.apply(generateTask, inputs)
}
}
= classLoader.createTaskFor(taskFactory, X509CertificateDeserializer::class.java) as Function<ByteArray, out Any?>
override val schemaForDocumentation: Schema = Schema(emptyList())

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.YearMonthDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.YearMonthSerializer.YearMonthProxy
import java.time.YearMonth
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxYearMonthSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(YearMonth::class.java),
proxyClass = classLoader.loadClassForSandbox(YearMonthProxy::class.java),
clazz = classLoader.toSandboxAnyClass(YearMonth::class.java),
proxyClass = classLoader.toSandboxAnyClass(YearMonthProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(YearMonthDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, YearMonthDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(YearMonth::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,30 +2,30 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.YearDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.YearSerializer.YearProxy
import java.time.Year
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxYearSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(Year::class.java),
proxyClass = classLoader.loadClassForSandbox(YearProxy::class.java),
clazz = classLoader.toSandboxAnyClass(Year::class.java),
proxyClass = classLoader.toSandboxAnyClass(YearProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(YearDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, YearDeserializer::class.java)
override val deserializationAliases: Set<Class<*>> = singleton(Year::class.java)
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,24 +2,24 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.ZoneIdDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.ZoneIdSerializer.ZoneIdProxy
import java.time.ZoneId
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxZoneIdSerializer(
classLoader: SandboxClassLoader,
private val executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(ZoneId::class.java),
proxyClass = classLoader.loadClassForSandbox(ZoneIdProxy::class.java),
clazz = classLoader.toSandboxAnyClass(ZoneId::class.java),
proxyClass = classLoader.toSandboxAnyClass(ZoneIdProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(ZoneIdDeserializer::class.java).newInstance()
private val task = classLoader.createTaskFor(taskFactory, ZoneIdDeserializer::class.java)
override val revealSubclassesInSchema: Boolean = true
@ -28,6 +28,6 @@ class SandboxZoneIdSerializer(
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return executor.apply(task, proxy)!!
return task.apply(proxy)!!
}
}

View File

@ -2,7 +2,7 @@ package net.corda.djvm.serialization.serializers
import net.corda.djvm.rewiring.SandboxClassLoader
import net.corda.djvm.serialization.deserializers.ZonedDateTimeDeserializer
import net.corda.djvm.serialization.loadClassForSandbox
import net.corda.djvm.serialization.toSandboxAnyClass
import net.corda.serialization.internal.amqp.CustomSerializer
import net.corda.serialization.internal.amqp.SerializerFactory
import net.corda.serialization.internal.amqp.custom.ZonedDateTimeSerializer.ZonedDateTimeProxy
@ -11,28 +11,28 @@ import java.time.ZoneId
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.util.Collections.singleton
import java.util.function.BiFunction
import java.util.function.Function
class SandboxZonedDateTimeSerializer(
classLoader: SandboxClassLoader,
executor: BiFunction<in Any, in Any?, out Any?>,
taskFactory: Function<in Any, out Function<in Any?, out Any?>>,
factory: SerializerFactory
) : CustomSerializer.Proxy<Any, Any>(
clazz = classLoader.loadClassForSandbox(ZonedDateTime::class.java),
proxyClass = classLoader.loadClassForSandbox(ZonedDateTimeProxy::class.java),
clazz = classLoader.toSandboxAnyClass(ZonedDateTime::class.java),
proxyClass = classLoader.toSandboxAnyClass(ZonedDateTimeProxy::class.java),
factory = factory
) {
private val task = classLoader.loadClassForSandbox(ZonedDateTimeDeserializer::class.java).newInstance()
private val creator: BiFunction<in Any?, in Any?, out Any?>
private val task = classLoader.createTaskFor(taskFactory, ZonedDateTimeDeserializer::class.java)
private val creator: Function<in Any?, out Any?>
init {
val createTask = clazz.getMethod(
"createDJVM",
classLoader.loadClassForSandbox(LocalDateTime::class.java),
classLoader.loadClassForSandbox(ZoneOffset::class.java),
classLoader.loadClassForSandbox(ZoneId::class.java)
classLoader.toSandboxClass(LocalDateTime::class.java),
classLoader.toSandboxClass(ZoneOffset::class.java),
classLoader.toSandboxClass(ZoneId::class.java)
)
creator = executor.andThen { input ->
creator = task.andThen { input ->
@Suppress("unchecked_cast")
createTask(null, *(input as Array<Any>))!!
}
@ -43,6 +43,6 @@ class SandboxZonedDateTimeSerializer(
override fun toProxy(obj: Any): Any = abortReadOnly()
override fun fromProxy(proxy: Any): Any {
return creator.apply(task, proxy)!!
return creator.apply(proxy)!!
}
}

View File

@ -27,11 +27,9 @@ class DeserializeBigDecimalTest : TestBase(KOTLIN) {
val sandboxBigInteger = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowBigDecimal::class.java).newInstance(),
sandboxBigInteger
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showBigDecimal = classLoader.createTaskFor(taskFactory, ShowBigDecimal::class.java)
val result = showBigDecimal.apply(sandboxBigInteger) ?: fail("Result cannot be null")
assertEquals(ShowBigDecimal().apply(bigDecimal), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -27,11 +27,9 @@ class DeserializeBigIntegerTest : TestBase(KOTLIN) {
val sandboxBigInteger = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowBigInteger::class.java).newInstance(),
sandboxBigInteger
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showBigInteger = classLoader.createTaskFor(taskFactory, ShowBigInteger::class.java)
val result = showBigInteger.apply(sandboxBigInteger) ?: fail("Result cannot be null")
assertEquals(ShowBigInteger().apply(bigInteger), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializeBitSetTest : TestBase(KOTLIN) {
val sandboxBitSet = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowBitSet::class.java).newInstance(),
sandboxBitSet
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showBitSet = classLoader.createTaskFor(taskFactory, ShowBitSet::class.java)
val result = showBitSet.apply(sandboxBitSet) ?: fail("Result cannot be null")
assertEquals(bitSet.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -54,11 +54,9 @@ class DeserializeCertificatesTest : TestBase(KOTLIN) {
val sandboxCertPath = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowCertPath::class.java).newInstance(),
sandboxCertPath
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showCertPath = classLoader.createTaskFor(taskFactory, ShowCertPath::class.java)
val result = showCertPath.apply(sandboxCertPath) ?: fail("Result cannot be null")
assertEquals(ShowCertPath().apply(certPath), localise(result.toString()))
assertThat(result::class.java.name).startsWith("sandbox.")
@ -80,11 +78,9 @@ class DeserializeCertificatesTest : TestBase(KOTLIN) {
val sandboxCertificate = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowCertificate::class.java).newInstance(),
sandboxCertificate
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showCertificate = classLoader.createTaskFor(taskFactory, ShowCertificate::class.java)
val result = showCertificate.apply(sandboxCertificate) ?: fail("Result cannot be null")
assertEquals(ShowCertificate().apply(certificate), localise(result.toString()))
assertThat(result::class.java.name).startsWith("sandbox.")
@ -116,11 +112,9 @@ class DeserializeCertificatesTest : TestBase(KOTLIN) {
val sandboxCRL = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowCRL::class.java).newInstance(),
sandboxCRL
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showCRL = classLoader.createTaskFor(taskFactory, ShowCRL::class.java)
val result = showCRL.apply(sandboxCRL) ?: fail("Result cannot be null")
assertEquals(ShowCRL().apply(crl), localise(result.toString()))
assertThat(result::class.java.name).startsWith("sandbox.")

View File

@ -25,11 +25,9 @@ class DeserializeClassTest : TestBase(KOTLIN) {
val sandboxInstant = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowClass::class.java).newInstance(),
sandboxInstant
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showClass = classLoader.createTaskFor(taskFactory, ShowClass::class.java)
val result = showClass.apply(sandboxInstant) ?: fail("Result cannot be null")
assertEquals("sandbox.${myClass.name}", result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -25,11 +25,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) {
val sandboxList = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringList::class.java).newInstance(),
sandboxList
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringList = classLoader.createTaskFor(taskFactory, ShowStringList::class.java)
val result = showStringList.apply(sandboxList) ?: fail("Result cannot be null")
assertEquals(stringList.lines.joinToString(), result.toString())
assertEquals("Hello, World, !", result.toString())
@ -52,11 +50,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) {
val sandboxSet = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowIntegerSet::class.java).newInstance(),
sandboxSet
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showIntegerSet = classLoader.createTaskFor(taskFactory, ShowIntegerSet::class.java)
val result = showIntegerSet.apply(sandboxSet) ?: fail("Result cannot be null")
assertEquals(integerSet.numbers.joinToString(), result.toString())
assertEquals("10, 3, 15, 2", result.toString())
@ -79,11 +75,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) {
val sandboxSet = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowIntegerSortedSet::class.java).newInstance(),
sandboxSet
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showIntegerSortedSet = classLoader.createTaskFor(taskFactory, ShowIntegerSortedSet::class.java)
val result = showIntegerSortedSet.apply(sandboxSet) ?: fail("Result cannot be null")
assertEquals(integerSortedSet.numbers.joinToString(), result.toString())
assertEquals("2, 3, 10, 15, 1000", result.toString())
@ -106,11 +100,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) {
val sandboxSet = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowLongNavigableSet::class.java).newInstance(),
sandboxSet
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showLongNavigableSet = classLoader.createTaskFor(taskFactory, ShowLongNavigableSet::class.java)
val result = showLongNavigableSet.apply(sandboxSet) ?: fail("Result cannot be null")
assertEquals(longNavigableSet.numbers.joinToString(), result.toString())
assertEquals("2, 3, 10, 15, 1000, 99955", result.toString())
@ -133,11 +125,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) {
val sandboxCollection = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowShortCollection::class.java).newInstance(),
sandboxCollection
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showShortCollection = classLoader.createTaskFor(taskFactory, ShowShortCollection::class.java)
val result = showShortCollection.apply(sandboxCollection) ?: fail("Result cannot be null")
assertEquals(shortCollection.numbers.joinToString(), result.toString())
assertEquals("10, 200, 3000", result.toString())
@ -160,11 +150,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) {
val sandboxSet = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowNonEmptyStringSet::class.java).newInstance(),
sandboxSet
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showNonEmptyStringSet = classLoader.createTaskFor(taskFactory, ShowNonEmptyStringSet::class.java)
val result = showNonEmptyStringSet.apply(sandboxSet) ?: fail("Result cannot be null")
assertEquals(nonEmptyStrings.lines.joinToString(), result.toString())
assertEquals("Hello, World, !", result.toString())
@ -187,11 +175,9 @@ class DeserializeCollectionsTest : TestBase(KOTLIN) {
val sandboxSet = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowHasEnumSet::class.java).newInstance(),
sandboxSet
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showHasEnumSet = classLoader.createTaskFor(taskFactory, ShowHasEnumSet::class.java)
val result = showHasEnumSet.apply(sandboxSet) ?: fail("Result cannot be null")
assertEquals(enumSet.values.toString(), result.toString())
assertEquals("[DOH]", result.toString())

View File

@ -23,11 +23,9 @@ class DeserializeCurrencyTest : TestBase(KOTLIN) {
val sandboxCurrency = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowCurrency::class.java).newInstance(),
sandboxCurrency
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showCurrency = classLoader.createTaskFor(taskFactory, ShowCurrency::class.java)
val result = showCurrency.apply(sandboxCurrency) ?: fail("Result cannot be null")
assertEquals(ShowCurrency().apply(currency), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -25,11 +25,9 @@ class DeserializeEnumSetTest : TestBase(KOTLIN) {
val sandboxEnumSet = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowEnumSet::class.java).newInstance(),
sandboxEnumSet
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showEnumSet = classLoader.createTaskFor(taskFactory, ShowEnumSet::class.java)
val result = showEnumSet.apply(sandboxEnumSet) ?: fail("Result cannot be null")
assertEquals(ShowEnumSet().apply(enumSet), result.toString())
assertEquals("EnumSet: [$value]'", result.toString())

View File

@ -24,11 +24,9 @@ class DeserializeEnumTest : TestBase(KOTLIN) {
val sandboxExample = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowExampleData::class.java).newInstance(),
sandboxExample
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showExampleData = classLoader.createTaskFor(taskFactory, ShowExampleData::class.java)
val result = showExampleData.apply(sandboxExample) ?: fail("Result cannot be null")
assertEquals(ShowExampleData().apply(example), result.toString())
assertEquals("Example: name='${value.name}', ordinal='${value.ordinal}'", result.toString())

View File

@ -24,11 +24,9 @@ class DeserializeGenericsTest : TestBase(KOTLIN) {
val sandboxWrapper = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowGenericWrapper::class.java).newInstance(),
sandboxWrapper
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showGenericWrapper = classLoader.createTaskFor(taskFactory, ShowGenericWrapper::class.java)
val result = showGenericWrapper.apply(sandboxWrapper) ?: fail("Result cannot be null")
assertEquals("Hello World!", result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)
@ -54,11 +52,9 @@ class DeserializeGenericsTest : TestBase(KOTLIN) {
val sandboxWrapped = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowConcreteWrapper::class.java).newInstance(),
sandboxWrapped
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showConcreteWrapper = classLoader.createTaskFor(taskFactory, ShowConcreteWrapper::class.java)
val result = showConcreteWrapper.apply(sandboxWrapped) ?: fail("Result cannot be null")
assertEquals("Concrete: first='Hello World', second='!'", result.toString())
}

View File

@ -26,11 +26,9 @@ class DeserializeInputStreamTest : TestBase(KOTLIN) {
val sandboxStream = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowInputStream::class.java).newInstance(),
sandboxStream
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showInputStream = classLoader.createTaskFor(taskFactory, ShowInputStream::class.java)
val result = showInputStream.apply(sandboxStream) ?: fail("Result cannot be null")
assertEquals(String(MESSAGE.byteInputStream().readFully()), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializeInstantTest : TestBase(KOTLIN) {
val sandboxInstant = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowInstant::class.java).newInstance(),
sandboxInstant
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showInstant = classLoader.createTaskFor(taskFactory, ShowInstant::class.java)
val result = showInstant.apply(sandboxInstant) ?: fail("Result cannot be null")
assertEquals(instant.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializeJavaWithMultipleConstructorsTest : TestBase(KOTLIN) {
val sandboxData = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowMultiData::class.java).newInstance(),
sandboxData
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showMultiData = classLoader.createTaskFor(taskFactory, ShowMultiData::class.java)
val result = showMultiData.apply(sandboxData) ?: fail("Result cannot be null")
assertThat(result.toString())
.isEqualTo("MultiConstructor[message='Hello World', bigNumber=9223372036854775807, tag=!]")

View File

@ -22,11 +22,9 @@ class DeserializeLocalDateTest : TestBase(KOTLIN) {
val sandboxDate = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowLocalDate::class.java).newInstance(),
sandboxDate
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showLocalDate = classLoader.createTaskFor(taskFactory, ShowLocalDate::class.java)
val result = showLocalDate.apply(sandboxDate) ?: fail("Result cannot be null")
assertEquals(date.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializeLocalDateTimeTest : TestBase(KOTLIN) {
val sandboxDateTime = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowLocalDateTime::class.java).newInstance(),
sandboxDateTime
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showLocalDateTime = classLoader.createTaskFor(taskFactory, ShowLocalDateTime::class.java)
val result = showLocalDateTime.apply( sandboxDateTime) ?: fail("Result cannot be null")
assertEquals(dateTime.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializeLocalTimeTest : TestBase(KOTLIN) {
val sandboxTime = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowLocalTime::class.java).newInstance(),
sandboxTime
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showLocalTime = classLoader.createTaskFor(taskFactory, ShowLocalTime::class.java)
val result = showLocalTime.apply(sandboxTime) ?: fail("Result cannot be null")
assertEquals(time.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -23,11 +23,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) {
val sandboxMap = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringMap::class.java).newInstance(),
sandboxMap
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringMap = classLoader.createTaskFor(taskFactory, ShowStringMap::class.java)
val result = showStringMap.apply(sandboxMap) ?: fail("Result cannot be null")
assertEquals(stringMap.values.entries.joinToString(), result.toString())
assertEquals("Open=Hello World, Close=Goodbye, Cruel World", result.toString())
@ -54,11 +52,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) {
val sandboxMap = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringSortedMap::class.java).newInstance(),
sandboxMap
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringSortedMap = classLoader.createTaskFor(taskFactory, ShowStringSortedMap::class.java)
val result = showStringSortedMap.apply(sandboxMap) ?: fail("Result cannot be null")
assertEquals(sortedMap.values.entries.joinToString(), result.toString())
assertEquals("10=Hello World, 50=Having Fun!, 100=Goodbye, Cruel World", result.toString())
@ -85,11 +81,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) {
val sandboxMap = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringNavigableMap::class.java).newInstance(),
sandboxMap
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringNavigableMap = classLoader.createTaskFor(taskFactory, ShowStringNavigableMap::class.java)
val result = showStringNavigableMap.apply(sandboxMap) ?: fail("Result cannot be null")
assertEquals(navigableMap.values.entries.joinToString(), result.toString())
assertEquals("1000=Hello World, 5000=Having Fun!, 10000=Goodbye, Cruel World", result.toString())
@ -116,11 +110,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) {
val sandboxMap = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringLinkedHashMap::class.java).newInstance(),
sandboxMap
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringLinkedHashMap = classLoader.createTaskFor(taskFactory, ShowStringLinkedHashMap::class.java)
val result = showStringLinkedHashMap.apply(sandboxMap) ?: fail("Result cannot be null")
assertEquals(linkedHashMap.values.entries.joinToString(), result.toString())
assertEquals("Close=Goodbye, Cruel World, Open=Hello World, During=Having Fun!", result.toString())
@ -147,11 +139,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) {
val sandboxMap = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringTreeMap::class.java).newInstance(),
sandboxMap
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringTreeMap = classLoader.createTaskFor(taskFactory, ShowStringTreeMap::class.java)
val result = showStringTreeMap.apply(sandboxMap) ?: fail("Result cannot be null")
assertEquals(treeMap.values.entries.joinToString(), result.toString())
assertEquals("1000=Hello World, 5000=Having Fun!, 10000=Goodbye, Cruel World", result.toString())
@ -177,11 +167,9 @@ class DeserializeMapsTest : TestBase(KOTLIN) {
val sandboxMap = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowEnumMap::class.java).newInstance(),
sandboxMap
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showEnumMap = classLoader.createTaskFor(taskFactory, ShowEnumMap::class.java)
val result = showEnumMap.apply(sandboxMap) ?: fail("Result cannot be null")
assertEquals(enumMap.toString(), result.toString())
assertEquals("{ONE=One!, TWO=Two!}", result.toString())

View File

@ -22,11 +22,9 @@ class DeserializeMonthDayTest : TestBase(KOTLIN) {
val sandboxMonthDay = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowMonthDay::class.java).newInstance(),
sandboxMonthDay
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showMonthDay = classLoader.createTaskFor(taskFactory, ShowMonthDay::class.java)
val result = showMonthDay.apply(sandboxMonthDay) ?: fail("Result cannot be null")
assertEquals(monthDay.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -24,11 +24,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringArray = classLoader.createTaskFor(taskFactory, ShowStringArray::class.java)
val result = showStringArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals(SANDBOX_STRING, result::class.java.name)
assertEquals("Hello, World, !", result.toString())
@ -52,11 +50,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowCharacterArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showCharacterArray = classLoader.createTaskFor(taskFactory, ShowCharacterArray::class.java)
val result = showCharacterArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals(SANDBOX_STRING, result::class.java.name)
assertEquals("Hello!", result.toString())
@ -79,11 +75,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowLongArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showLongArray = classLoader.createTaskFor(taskFactory, ShowLongArray::class.java)
val result = showLongArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Long", result::class.java.name)
assertEquals("15000", result.toString())
@ -106,11 +100,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowIntegerArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showIntegerArray = classLoader.createTaskFor(taskFactory, ShowIntegerArray::class.java)
val result = showIntegerArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Integer", result::class.java.name)
assertEquals("1500", result.toString())
@ -133,11 +125,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowShortArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showShortArray = classLoader.createTaskFor(taskFactory, ShowShortArray::class.java)
val result = showShortArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Integer", result::class.java.name)
assertEquals("1500", result.toString())
@ -160,11 +150,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowByteArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showByteArray = classLoader.createTaskFor(taskFactory, ShowByteArray::class.java)
val result = showByteArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Integer", result::class.java.name)
assertEquals("150", result.toString())
@ -187,11 +175,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowDoubleArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showDoubleArray = classLoader.createTaskFor(taskFactory, ShowDoubleArray::class.java)
val result = showDoubleArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Double", result::class.java.name)
assertEquals("15000.0", result.toString())
@ -214,11 +200,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowFloatArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showFloatArray = classLoader.createTaskFor(taskFactory, ShowFloatArray::class.java)
val result = showFloatArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Float", result::class.java.name)
assertEquals("150.0", result.toString())
@ -241,11 +225,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowBooleanArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showBooleanArray = classLoader.createTaskFor(taskFactory, ShowBooleanArray::class.java)
val result = showBooleanArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Boolean", result::class.java.name)
assertEquals("true", result.toString())
@ -269,11 +251,9 @@ class DeserializeObjectArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowUUIDArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showUUIDArray = classLoader.createTaskFor(taskFactory, ShowUUIDArray::class.java)
val result = showUUIDArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals(SANDBOX_STRING, result::class.java.name)
assertEquals(uuid.toString(), result.toString())

View File

@ -22,11 +22,9 @@ class DeserializeOffsetDateTimeTest : TestBase(KOTLIN) {
val sandboxDateTime = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowOffsetDateTime::class.java).newInstance(),
sandboxDateTime
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showOffsetDateTime = classLoader.createTaskFor(taskFactory, ShowOffsetDateTime::class.java)
val result = showOffsetDateTime.apply(sandboxDateTime) ?: fail("Result cannot be null")
assertEquals(dateTime.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializeOffsetTimeTest : TestBase(KOTLIN) {
val sandboxTime = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowOffsetTime::class.java).newInstance(),
sandboxTime
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showOffsetTime = classLoader.createTaskFor(taskFactory, ShowOffsetTime::class.java)
val result = showOffsetTime.apply(sandboxTime) ?: fail("Result cannot be null")
assertEquals(time.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -31,11 +31,9 @@ class DeserializeOpaqueBytesSubSequenceTest : TestBase(KOTLIN) {
val sandboxBytes = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowOpaqueBytesSubSequence::class.java).newInstance(),
sandboxBytes
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showOpaqueBytesSubSequence = classLoader.createTaskFor(taskFactory, ShowOpaqueBytesSubSequence::class.java)
val result = showOpaqueBytesSubSequence.apply(sandboxBytes) ?: fail("Result cannot be null")
assertEquals(MESSAGE.substring(OFFSET), String(result as ByteArray))
assertEquals(String(subSequence.copyBytes()), String(result))

View File

@ -22,11 +22,9 @@ class DeserializeOptionalTest : TestBase(KOTLIN) {
val sandboxOptional = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowOptional::class.java).newInstance(),
sandboxOptional
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showOptional = classLoader.createTaskFor(taskFactory, ShowOptional::class.java)
val result = showOptional.apply(sandboxOptional) ?: fail("Result cannot be null")
assertEquals("Optional -> Optional[Hello World!]", result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)
@ -43,11 +41,9 @@ class DeserializeOptionalTest : TestBase(KOTLIN) {
val sandboxOptional = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowOptional::class.java).newInstance(),
sandboxOptional
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showOptional = classLoader.createTaskFor(taskFactory, ShowOptional::class.java)
val result = showOptional.apply(sandboxOptional) ?: fail("Result cannot be null")
assertEquals("Optional -> Optional.empty", result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializePeriodTest : TestBase(KOTLIN) {
val sandboxPeriod = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowPeriod::class.java).newInstance(),
sandboxPeriod
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showPeriod = classLoader.createTaskFor(taskFactory, ShowPeriod::class.java)
val result = showPeriod.apply(sandboxPeriod) ?: fail("Result cannot be null")
assertEquals(period.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -23,11 +23,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowCharArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showCharArray = classLoader.createTaskFor(taskFactory, ShowCharArray::class.java)
val result = showCharArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals(SANDBOX_STRING, result::class.java.name)
assertEquals("Hello!", result.toString())
@ -50,11 +48,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowIntegerArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showIntegerArray = classLoader.createTaskFor(taskFactory, ShowIntegerArray::class.java)
val result = showIntegerArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Integer", result::class.java.name)
assertEquals("1500", result.toString())
@ -77,11 +73,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowLongArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showLongArray = classLoader.createTaskFor(taskFactory, ShowLongArray::class.java)
val result = showLongArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Long", result::class.java.name)
assertEquals("15000", result.toString())
@ -104,11 +98,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowShortArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showShortArray = classLoader.createTaskFor(taskFactory, ShowShortArray::class.java)
val result = showShortArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Integer", result::class.java.name)
assertEquals("1500", result.toString())
@ -131,11 +123,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowByteArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showByteArray = classLoader.createTaskFor(taskFactory, ShowByteArray::class.java)
val result = showByteArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Integer", result::class.java.name)
assertEquals("150", result.toString())
@ -158,11 +148,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowBooleanArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showBooleanArray = classLoader.createTaskFor(taskFactory, ShowBooleanArray::class.java)
val result = showBooleanArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Boolean", result::class.java.name)
assertEquals("true", result.toString())
@ -185,11 +173,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowDoubleArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showDoubleArray = classLoader.createTaskFor(taskFactory, ShowDoubleArray::class.java)
val result = showDoubleArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Double", result::class.java.name)
assertEquals("15000.0", result.toString())
@ -212,11 +198,9 @@ class DeserializePrimitiveArraysTest : TestBase(KOTLIN) {
val sandboxArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowFloatArray::class.java).newInstance(),
sandboxArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showFloatArray = classLoader.createTaskFor(taskFactory, ShowFloatArray::class.java)
val result = showFloatArray.apply(sandboxArray) ?: fail("Result cannot be null")
assertEquals("sandbox.java.lang.Float", result::class.java.name)
assertEquals("1500.0", result.toString())

View File

@ -24,11 +24,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) {
val sandboxProtonJ = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowUnsignedLong::class.java).newInstance(),
sandboxProtonJ
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showUnsignedLong = classLoader.createTaskFor(taskFactory, ShowUnsignedLong::class.java)
val result = showUnsignedLong.apply(sandboxProtonJ) ?: fail("Result cannot be null")
assertEquals(protonJ.number.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)
@ -51,11 +49,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) {
val sandboxProtonJ = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowUnsignedInteger::class.java).newInstance(),
sandboxProtonJ
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showUnsignedInteger = classLoader.createTaskFor(taskFactory, ShowUnsignedInteger::class.java)
val result = showUnsignedInteger.apply(sandboxProtonJ) ?: fail("Result cannot be null")
assertEquals(protonJ.number.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)
@ -78,11 +74,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) {
val sandboxProtonJ = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowUnsignedShort::class.java).newInstance(),
sandboxProtonJ
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showUnsignedShort = classLoader.createTaskFor(taskFactory, ShowUnsignedShort::class.java)
val result = showUnsignedShort.apply(sandboxProtonJ) ?: fail("Result cannot be null")
assertEquals(protonJ.number.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)
@ -105,11 +99,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) {
val sandboxProtonJ = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowUnsignedByte::class.java).newInstance(),
sandboxProtonJ
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showUnsignedByte = classLoader.createTaskFor(taskFactory, ShowUnsignedByte::class.java)
val result = showUnsignedByte.apply(sandboxProtonJ) ?: fail("Result cannot be null")
assertEquals(protonJ.number.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)
@ -132,11 +124,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) {
val sandboxProtonJ = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowDecimal128::class.java).newInstance(),
sandboxProtonJ
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showDecimal128 = classLoader.createTaskFor(taskFactory, ShowDecimal128::class.java)
val result = showDecimal128.apply(sandboxProtonJ) ?: fail("Result cannot be null")
assertThat(result)
.isEqualTo(protonJ.number.let { longArrayOf(it.mostSignificantBits, it.leastSignificantBits) })
@ -159,11 +149,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) {
val sandboxProtonJ = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowDecimal64::class.java).newInstance(),
sandboxProtonJ
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showDecimal64 = classLoader.createTaskFor(taskFactory, ShowDecimal64::class.java)
val result = showDecimal64.apply(sandboxProtonJ) ?: fail("Result cannot be null")
assertEquals(protonJ.number.bits.toString(), result.toString())
}
@ -185,11 +173,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) {
val sandboxProtonJ = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowDecimal32::class.java).newInstance(),
sandboxProtonJ
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showDecimal32 = classLoader.createTaskFor(taskFactory, ShowDecimal32::class.java)
val result = showDecimal32.apply(sandboxProtonJ) ?: fail("Result cannot be null")
assertEquals(protonJ.number.bits.toString(), result.toString())
}
@ -211,11 +197,9 @@ class DeserializeProtonJTest : TestBase(KOTLIN) {
val sandboxProtonJ = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowSymbol::class.java).newInstance(),
sandboxProtonJ
) ?: fail("Result cannot be null")
val executor = classLoader.createRawTaskFactory()
val taskFactory = classLoader.createTaskFor(executor, ShowSymbol::class.java)
val result = taskFactory.apply(sandboxProtonJ) ?: fail("Result cannot be null")
assertEquals(protonJ.symbol.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -43,11 +43,9 @@ class DeserializePublicKeyTest : TestBase(KOTLIN) {
val sandboxKey = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowPublicKey::class.java).newInstance(),
sandboxKey
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showPublicKey = classLoader.createTaskFor(taskFactory, ShowPublicKey::class.java)
val result = showPublicKey.apply(sandboxKey) ?: fail("Result cannot be null")
assertEquals(ShowPublicKey().apply(publicKey), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)
@ -73,11 +71,9 @@ class DeserializePublicKeyTest : TestBase(KOTLIN) {
val sandboxKey = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowPublicKey::class.java).newInstance(),
sandboxKey
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showPublicKey = classLoader.createTaskFor(taskFactory, ShowPublicKey::class.java)
val result = showPublicKey.apply(sandboxKey) ?: fail("Result cannot be null")
assertEquals(ShowPublicKey().apply(compositeData), result.toString())
}

View File

@ -19,13 +19,11 @@ class DeserializeStringBufferTest : TestBase(KOTLIN) {
sandbox {
_contextSerializationEnv.set(createSandboxSerializationEnv(classLoader))
val sandboxBigInteger = data.deserializeFor(classLoader)
val sandboxBuffer = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringBuffer::class.java).newInstance(),
sandboxBigInteger
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringBuffer = classLoader.createTaskFor(taskFactory, ShowStringBuffer::class.java)
val result = showStringBuffer.apply(sandboxBuffer) ?: fail("Result cannot be null")
assertEquals(ShowStringBuffer().apply(buffer), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializeStringTest : TestBase(KOTLIN) {
val sandboxString = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringMessage::class.java).newInstance(),
sandboxString
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringMessage = classLoader.createTaskFor(taskFactory, ShowStringMessage::class.java)
val result = showStringMessage.apply(sandboxString) ?: fail("Result cannot be null")
assertEquals(stringMessage.message, result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)
@ -51,11 +49,9 @@ class DeserializeStringTest : TestBase(KOTLIN) {
val sandboxListArray = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowStringListOfArray::class.java).newInstance(),
sandboxListArray
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showStringListOfArray = classLoader.createTaskFor(taskFactory, ShowStringListOfArray::class.java)
val result = showStringListOfArray.apply(sandboxListArray) ?: fail("Result cannot be null")
assertEquals(stringListArray.data.flatMap(Array<String>::toList).joinToString(), result.toString())
}

View File

@ -22,11 +22,9 @@ class DeserializeYearMonthTest : TestBase(KOTLIN) {
val sandboxYearMonth = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowYearMonth::class.java).newInstance(),
sandboxYearMonth
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showYearMonth = classLoader.createTaskFor(taskFactory, ShowYearMonth::class.java)
val result = showYearMonth.apply(sandboxYearMonth) ?: fail("Result cannot be null")
assertEquals(yearMonth.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializeYearTest : TestBase(KOTLIN) {
val sandboxYear = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowYear::class.java).newInstance(),
sandboxYear
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showYear = classLoader.createTaskFor(taskFactory, ShowYear::class.java)
val result = showYear.apply(sandboxYear) ?: fail("Result cannot be null")
assertEquals(year.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -34,11 +34,9 @@ class DeserializeZoneIdTest : TestBase(KOTLIN) {
val sandboxZoneId = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowZoneId::class.java).newInstance(),
sandboxZoneId
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showZoneId = classLoader.createTaskFor(taskFactory, ShowZoneId::class.java)
val result = showZoneId.apply(sandboxZoneId) ?: fail("Result cannot be null")
assertEquals(zoneId.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -22,11 +22,9 @@ class DeserializeZonedDateTimeTest : TestBase(KOTLIN) {
val sandboxDateTime = data.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowZonedDateTime::class.java).newInstance(),
sandboxDateTime
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showZonedDateTime = classLoader.createTaskFor(taskFactory, ShowZonedDateTime::class.java)
val result = showZonedDateTime.apply(sandboxDateTime) ?: fail("Result cannot be null")
assertEquals(dateTime.toString(), result.toString())
assertEquals(SANDBOX_STRING, result::class.java.name)

View File

@ -45,11 +45,9 @@ class SafeDeserialisationTest : TestBase(KOTLIN) {
val sandboxData = evilData.deserializeFor(classLoader)
val executor = createExecutorFor(classLoader)
val result = executor.apply(
classLoader.loadClassForSandbox(ShowInnocentData::class.java).newInstance(),
sandboxData
) ?: fail("Result cannot be null")
val taskFactory = classLoader.createRawTaskFactory()
val showInnocentData = classLoader.createTaskFor(taskFactory, ShowInnocentData::class.java)
val result = showInnocentData.apply(sandboxData) ?: fail("Result cannot be null")
// Check that we have deserialised the data without instantiating the Evil class.
assertThat(result.toString())

View File

@ -11,7 +11,6 @@ import net.corda.djvm.SandboxRuntimeContext
import net.corda.djvm.analysis.AnalysisConfiguration
import net.corda.djvm.analysis.Whitelist.Companion.MINIMAL
import net.corda.djvm.execution.ExecutionProfile.*
import net.corda.djvm.execution.SandboxRuntimeException
import net.corda.djvm.messages.Severity
import net.corda.djvm.messages.Severity.*
import net.corda.djvm.rewiring.SandboxClassLoader
@ -21,12 +20,10 @@ import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.fail
import java.io.File
import java.lang.reflect.InvocationTargetException
import java.nio.file.Files.exists
import java.nio.file.Files.isDirectory
import java.nio.file.Path
import java.nio.file.Paths
import java.util.function.BiFunction
import kotlin.concurrent.thread
@Suppress("unused", "MemberVisibilityCanBePrivate")
@ -121,21 +118,4 @@ abstract class TestBase(type: SandboxType) {
}.join()
throw thrownException ?: return
}
fun createExecutorFor(classLoader: SandboxClassLoader): BiFunction<in Any, in Any?, out Any?> {
val taskClass = classLoader.loadClass("sandbox.RawTask")
val taskApply = taskClass.getDeclaredMethod("apply", Any::class.java)
val taskConstructor = taskClass.getDeclaredConstructor(classLoader.loadClass("sandbox.java.util.function.Function"))
return BiFunction { userTask, arg ->
try {
taskApply(taskConstructor.newInstance(userTask), arg)
} catch (ex: InvocationTargetException) {
val target = ex.targetException
throw when (target) {
is RuntimeException, is Error -> target
else -> SandboxRuntimeException(target.message, target)
}
}
}
}
}
}