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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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