From 0b8820265ed769b623525e06cb8af06a61e67c33 Mon Sep 17 00:00:00 2001 From: sofusmortensen Date: Thu, 24 Mar 2016 13:09:04 +0000 Subject: [PATCH] removed couple of warnings --- .../main/kotlin/core/serialization/Kryo.kt | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/core/src/main/kotlin/core/serialization/Kryo.kt b/core/src/main/kotlin/core/serialization/Kryo.kt index a0403e0eb4..335329a724 100644 --- a/core/src/main/kotlin/core/serialization/Kryo.kt +++ b/core/src/main/kotlin/core/serialization/Kryo.kt @@ -179,11 +179,11 @@ class ImmutableClassSerializer(val klass: KClass) : Serializer() } } -inline fun Kryo.useClassLoader(cl: ClassLoader, body: () -> Unit) { +inline fun Kryo.useClassLoader(cl: ClassLoader, body: () -> T) : T { val tmp = this.classLoader this.classLoader = cl try { - body() + return body() } finally { if (tmp != null) { @@ -225,27 +225,22 @@ fun createKryo(k: Kryo = core.serialization.Kryo2()): Kryo { } + @Suppress("UNCHECKED_CAST") override fun read(kryo: Kryo, input: Input, type: Class): WireTransaction { var inputs = kryo.readClassAndObject( input ) as List var attachments = kryo.readClassAndObject( input ) as List - if (kryo is core.serialization.Kryo2) { + val attachmentStorage = (kryo as? core.serialization.Kryo2)?.attachmentStorage - // .filterNotNull in order for TwoPartyTradeProtocolTests.checkDependenciesOfSaleAssetAreResolved test to run - val classLoader = core.node.ClassLoader.create( attachments?.map { kryo.attachmentStorage?.openAttachment(it) }.filterNotNull() ) + // .filterNotNull in order for TwoPartyTradeProtocolTests.checkDependenciesOfSaleAssetAreResolved test to run + val classLoader = core.node.ClassLoader.create( attachments.map { attachmentStorage?.openAttachment(it) }.filterNotNull() ) - kryo.useClassLoader(classLoader) { - var outputs = kryo.readClassAndObject(input) as List - var commands = kryo.readClassAndObject(input) as List + return kryo.useClassLoader(classLoader) { + var outputs = kryo.readClassAndObject(input) as List + var commands = kryo.readClassAndObject(input) as List - return WireTransaction(inputs, attachments, outputs, commands) - } + return WireTransaction(inputs, attachments, outputs, commands) } - - var outputs = kryo.readClassAndObject(input) as List - var commands = kryo.readClassAndObject(input) as List - - return WireTransaction(inputs, attachments, outputs, commands) } })