diff --git a/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt b/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt index 348ae98f24..174cb301fc 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/AMQPSerializationScheme.kt @@ -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, - private val executor: BiFunction, + private val taskFactory: Function>, 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)) } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt index bd15c6da6c..f286fcf2a8 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/Serialization.kt @@ -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 { +@Suppress("NOTHING_TO_INLINE") +inline fun SandboxClassLoader.toSandboxAnyClass(clazz: Class<*>): Class { @Suppress("unchecked_cast") - return loadClassForSandbox(ClassSource.fromClassName(clazz.name)) as Class + return toSandboxClass(clazz) as Class } 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 = 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, AMQPSerializer> = 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 SerializedBytes.deserializeFor(classLoader: SandboxClassLoader): Any { - val clazz = classLoader.loadClassForSandbox(T::class.java) + val clazz = classLoader.toSandboxClass(T::class.java) return deserializeTo(clazz, classLoader) } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt index b6a2791944..986bb688d0 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxBitSetSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt index e7380aaeaf..ce916ab671 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCertPathSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt index 3793808587..8531d79f1e 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCharacterSerializer.kt @@ -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 -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Char::class.javaObjectType)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Char::class.javaObjectType)) { override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt index 28b275a62a..ebf7270645 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxClassSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( clazz = Class::class.java as Class, - 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 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", diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt index 3aad78113f..a7b195098b 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCollectionSerializer.kt @@ -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, + taskFactory: Function>, private val localFactory: LocalSerializerFactory -) : CustomSerializer.Implements(clazz = classLoader.loadClassForSandbox(Collection::class.java)) { +) : CustomSerializer.Implements(clazz = classLoader.toSandboxAnyClass(Collection::class.java)) { + @Suppress("unchecked_cast") private val creator: Function, 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, out Any?> private val unsupportedTypes: Set> = 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): Map.Entry, Class>> diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt index 9eee16cb33..6bb3f90360 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxCurrencySerializer.kt @@ -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, + taskFactory: Function>, basicInput: Function -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Currency::class.java)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Currency::class.java)) { private val creator: Function 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> = Collections.singleton(Currency::class.java) + override val deserializationAliases: Set> = singleton(Currency::class.java) override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt index 7f5da69f5e..283700a8fb 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal128Serializer.kt @@ -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 -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Decimal128::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Decimal128::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(Decimal128Deserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, Decimal128Deserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt index d0d8016683..4037b5e9b6 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal32Serializer.kt @@ -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 -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Decimal32::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Decimal32::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(Decimal32Deserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, Decimal32Deserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt index c77820712d..e10967e0b3 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDecimal64Serializer.kt @@ -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 -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Decimal64::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Decimal64::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(Decimal64Deserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, Decimal64Deserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt index 48586ce4df..d1ab4eb2ab 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxDurationSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt index fedb92450a..6729ca0c4c 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSerializer.kt @@ -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, + taskFactory: Function>, private val localFactory: LocalSerializerFactory -) : CustomSerializer.Implements(clazz = classLoader.loadClassForSandbox(Enum::class.java)) { +) : CustomSerializer.Implements(clazz = classLoader.toSandboxAnyClass(Enum::class.java)) { + @Suppress("unchecked_cast") private val describer: Function, Array> - - init { - val describeTask = classLoader.loadClassForSandbox(DescribeEnum::class.java).newInstance() - describer = Function { inputs -> - @Suppress("unchecked_cast") - executor.apply(describeTask, inputs) as Array - } - } + = classLoader.createTaskFor(taskFactory, DescribeEnum::class.java) as Function, Array> override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt index fe839f2b5c..1d0fa576d6 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxEnumSetSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = singleton( - SandboxClassSerializer(classLoader, executor, factory) + SandboxClassSerializer(classLoader, taskFactory, factory) ) override val deserializationAliases: Set> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt index c7b6465072..c4f944d4bd 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInputStreamSerializer.kt @@ -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 -) : CustomSerializer.Implements(classLoader.loadClassForSandbox(InputStream::class.java)) { + taskFactory: Function> +) : CustomSerializer.Implements(classLoader.toSandboxAnyClass(InputStream::class.java)) { + @Suppress("unchecked_cast") private val decoder: Function - - init { - val decodeTask = classLoader.loadClassForSandbox(InputStreamDeserializer::class.java).newInstance() - decoder = Function { inputs -> - executor.apply(decodeTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, InputStreamDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt index ea867b146a..452b6d1066 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxInstantSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt index 4a8cbb256b..11c324c03e 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt index d027a5b61c..af2a832027 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalDateTimeSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt index 87dfa15e26..ab54302539 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxLocalTimeSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt index 2489b53742..c718147799 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMapSerializer.kt @@ -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, + taskFactory: Function>, private val localFactory: LocalSerializerFactory -) : CustomSerializer.Implements(clazz = classLoader.loadClassForSandbox(Map::class.java)) { +) : CustomSerializer.Implements(clazz = classLoader.toSandboxAnyClass(Map::class.java)) { + @Suppress("unchecked_cast") private val creator: Function, 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, 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): Map.Entry, Class>> diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt index cd489228b2..c42c13946b 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxMonthDaySerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt index 54091ab2be..58dd564ca6 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetDateTimeSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt index 284465a4de..e452a281ef 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOffsetTimeSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt index 7d41b81930..944cf19437 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOpaqueBytesSubSequenceSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt index 733ceabc93..39eeb015a7 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxOptionalSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt index 31ad835f1c..836acbb3ca 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPeriodSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt index b5eeb43927..6499d6cb5a 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPrimitiveSerializer.kt @@ -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 -) : CustomSerializer.Is(classLoader.loadClassForSandbox(clazz)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(clazz)) { override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt index 4bbca81690..1806f43f2c 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxPublicKeySerializer.kt @@ -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 -) : CustomSerializer.Implements(classLoader.loadClassForSandbox(PublicKey::class.java)) { + taskFactory: Function> +) : CustomSerializer.Implements(classLoader.toSandboxAnyClass(PublicKey::class.java)) { + @Suppress("unchecked_cast") private val decoder: Function - - init { - val decodeTask = classLoader.loadClassForSandbox(PublicKeyDecoder::class.java).newInstance() - decoder = Function { inputs -> - executor.apply(decodeTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, PublicKeyDecoder::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt index 95ce4a7694..ade7c033b3 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxSymbolSerializer.kt @@ -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, + taskFactory: Function>, basicInput: Function -) : CustomSerializer.Is(classLoader.loadClassForSandbox(Symbol::class.java)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(Symbol::class.java)) { private val transformer: Function 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 + transformer = basicInput.andThen(transformTask) as Function } override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt index 765a406e1a..6482588ca7 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxToStringSerializer.kt @@ -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, + taskFactory: Function>, basicInput: Function -) : CustomSerializer.Is(classLoader.loadClassForSandbox(unsafeClass)) { +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(unsafeClass)) { private val creator: Function 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> = singleton(unsafeClass) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt index 30a208471a..df45ab0ea8 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedByteSerializer.kt @@ -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 -) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedByte::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(UnsignedByte::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(UnsignedByteDeserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, UnsignedByteDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt index 15b7ee6bcb..73c0b7a071 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedIntegerSerializer.kt @@ -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 -) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedInteger::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(UnsignedInteger::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(UnsignedIntegerDeserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, UnsignedIntegerDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt index d63d7469da..66370c443c 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedLongSerializer.kt @@ -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 -) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedLong::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(UnsignedLong::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(UnsignedLongDeserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, UnsignedLongDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt index 6eaa91b9ef..d292531634 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxUnsignedShortSerializer.kt @@ -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 -) : CustomSerializer.Is(classLoader.loadClassForSandbox(UnsignedShort::class.java)) { + taskFactory: Function> +) : CustomSerializer.Is(classLoader.toSandboxAnyClass(UnsignedShort::class.java)) { + @Suppress("unchecked_cast") private val transformer: Function - - init { - val transformTask = classLoader.loadClassForSandbox(UnsignedShortDeserializer::class.java).newInstance() - transformer = Function { inputs -> - executor.apply(transformTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, UnsignedShortDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt index a9f4ae85a2..44ef1c4507 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CRLSerializer.kt @@ -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 -) : CustomSerializer.Implements(classLoader.loadClassForSandbox(X509CRL::class.java)) { + taskFactory: Function> +) : CustomSerializer.Implements(classLoader.toSandboxAnyClass(X509CRL::class.java)) { + @Suppress("unchecked_cast") private val generator: Function - - init { - val generateTask = classLoader.loadClassForSandbox(X509CRLDeserializer::class.java).newInstance() - generator = Function { inputs -> - executor.apply(generateTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, X509CRLDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt index ccb8d3c266..669403359f 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxX509CertificateSerializer.kt @@ -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 -) : CustomSerializer.Implements(classLoader.loadClassForSandbox(X509Certificate::class.java)) { + taskFactory: Function> +) : CustomSerializer.Implements(classLoader.toSandboxAnyClass(X509Certificate::class.java)) { + @Suppress("unchecked_cast") private val generator: Function - - init { - val generateTask = classLoader.loadClassForSandbox(X509CertificateDeserializer::class.java).newInstance() - generator = Function { inputs -> - executor.apply(generateTask, inputs) - } - } + = classLoader.createTaskFor(taskFactory, X509CertificateDeserializer::class.java) as Function override val schemaForDocumentation: Schema = Schema(emptyList()) diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt index 6c91ca9a03..3b31d33763 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearMonthSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt index 3d01eb1ff8..d2fef146bd 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxYearSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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> = 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt index 6ca73ee520..018e37fe27 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZoneIdSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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)!! } } diff --git a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt index 5ef4f04f52..fa20800c1b 100644 --- a/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt +++ b/src/main/kotlin/net/corda/djvm/serialization/serializers/SandboxZonedDateTimeSerializer.kt @@ -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, + taskFactory: Function>, factory: SerializerFactory ) : CustomSerializer.Proxy( - 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 + private val task = classLoader.createTaskFor(taskFactory, ZonedDateTimeDeserializer::class.java) + private val creator: Function 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))!! } @@ -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)!! } } diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt index 58dc242a98..48864e8977 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigDecimalTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt index b89e2443ee..52785f687e 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBigIntegerTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt index 5b59a1fe4f..5ca8297121 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeBitSetTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt index ce8b0b33d5..95e6d48b47 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCertificatesTest.kt @@ -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.") diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt index 13b7a4f30e..085301f7f6 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeClassTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt index 2548ad88d5..3b109550a4 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCollectionsTest.kt @@ -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()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt index aa5870951e..a30b088e49 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeCurrencyTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt index 2dba16c4ed..6f70ce5285 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumSetTest.kt @@ -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()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt index 2ff7d78e39..4d4784a5c2 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeEnumTest.kt @@ -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()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt index 5e887e1b4b..815351467c 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeGenericsTest.kt @@ -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()) } diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt index 84cdd80712..d8aa937089 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInputStreamTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt index 2316de6dfa..b634aafc60 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeInstantTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt index 719d28a03e..7fc4d458c4 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeJavaWithMultipleConstructorsTest.kt @@ -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=!]") diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt index 007ca86548..4d11d4b936 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt index 1dd9debfbe..69f48a4611 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalDateTimeTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt index 2bfb4c2956..21360d3606 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeLocalTimeTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt index b4f8d692ef..e680d4d471 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMapsTest.kt @@ -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()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt index b9e7fac533..7f0a19028c 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeMonthDayTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt index b1b1a74928..47cd38f17b 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeObjectArraysTest.kt @@ -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()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt index cfc004522e..c17b2824d5 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetDateTimeTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt index a9eaad89f4..38b197f227 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOffsetTimeTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt index 519a86e6e3..a91bcba6ca 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOpaqueBytesSubSequenceTest.kt @@ -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)) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt index 8104f282ab..da085d6299 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeOptionalTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt index 2784dbd8aa..cdd95affa6 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePeriodTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt index 4cb3b4b30a..3187763f37 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePrimitiveArraysTest.kt @@ -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()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt index 2de052b5d1..5b3be55607 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeProtonJTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt index e6834d0a39..633d179be6 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializePublicKeyTest.kt @@ -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()) } diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt index 6ae12c8c66..9de18f8a3f 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringBufferTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt index 860952a8ab..f0004b5d21 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeStringTest.kt @@ -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::toList).joinToString(), result.toString()) } diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt index 0369972dc6..1589cd4f5f 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearMonthTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt index 5056586636..450ea05723 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeYearTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt index 27afdf6978..278dd6f629 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZoneIdTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt index 70a8f6b03b..df30c9208b 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/DeserializeZonedDateTimeTest.kt @@ -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) diff --git a/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt b/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt index cf7d9cd8be..6aa5d5b520 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/SafeDeserialisationTest.kt @@ -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()) diff --git a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt index 29af995f0f..6c698dfb3d 100644 --- a/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt +++ b/src/test/kotlin/net/corda/djvm/serialization/TestBase.kt @@ -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 { - 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) - } - } - } - } -} \ No newline at end of file +}