Fingerprint for Exception class reverted to V3 (fixes CORDA-2227 & CORDA-2292) (#4386)

This commit is contained in:
Shams Asari 2018-12-07 18:57:51 +00:00 committed by GitHub
parent c31da13c70
commit b020e602ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 23 deletions

View File

@ -65,17 +65,25 @@ abstract class CustomSerializer<T : Any> : AMQPSerializer<T>, SerializerFor {
override val schemaForDocumentation = Schema(emptyList()) override val schemaForDocumentation = Schema(emptyList())
override fun isSerializerFor(clazz: Class<*>): Boolean = clazz == this.clazz override fun isSerializerFor(clazz: Class<*>): Boolean = clazz == this.clazz
override val type: Type get() = clazz override val type: Type get() = clazz
override val typeDescriptor: Symbol by lazy { override val typeDescriptor: Symbol by lazy {
Symbol.valueOf("$DESCRIPTOR_DOMAIN:${FingerprintWriter(false).write(arrayOf(superClassSerializer.typeDescriptor.toString(), AMQPTypeIdentifiers.nameForType(clazz)).joinToString()).fingerprint}") val fingerprint = FingerprintWriter()
.write(superClassSerializer.typeDescriptor)
.write(AMQPTypeIdentifiers.nameForType(clazz))
.fingerprint
Symbol.valueOf("$DESCRIPTOR_DOMAIN:$fingerprint")
} }
private val typeNotation: TypeNotation = RestrictedType( private val typeNotation: TypeNotation = RestrictedType(
AMQPTypeIdentifiers.nameForType(clazz), AMQPTypeIdentifiers.nameForType(clazz),
null, null,
emptyList(), emptyList(),
AMQPTypeIdentifiers.nameForType(superClassSerializer.type), AMQPTypeIdentifiers.nameForType(superClassSerializer.type),
Descriptor(typeDescriptor), Descriptor(typeDescriptor),
emptyList()) emptyList()
)
override fun writeClassInfo(output: SerializationOutput) { override fun writeClassInfo(output: SerializationOutput) {
output.writeTypeNotations(typeNotation) output.writeTypeNotations(typeNotation)

View File

@ -45,7 +45,7 @@ class TypeModellingFingerPrinter(
* Wrapper for the [Hasher] we use to generate fingerprints, providing methods for writing various kinds of content * Wrapper for the [Hasher] we use to generate fingerprints, providing methods for writing various kinds of content
* into the hash. * into the hash.
*/ */
internal class FingerprintWriter(debugEnabled: Boolean) { internal class FingerprintWriter(debugEnabled: Boolean = false) {
companion object { companion object {
private const val ARRAY_HASH: String = "Array = true" private const val ARRAY_HASH: String = "Array = true"

View File

@ -0,0 +1,14 @@
package net.corda.serialization.internal
import net.corda.serialization.internal.amqp.custom.ThrowableSerializer
import net.corda.serialization.internal.amqp.testutils.testDefaultFactoryNoEvolution
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
class SerializationCompatibilityTests {
@Test
fun `fingerprint is stable`() {
val factory = testDefaultFactoryNoEvolution().apply { register(ThrowableSerializer(this)) }
assertThat(factory.get(Exception::class.java).typeDescriptor.toString()).isEqualTo("net.corda:ApZ2a/36VVskaoDZMbiZ8A==")
}
}

View File

@ -2,7 +2,6 @@ package net.corda.blobinspector
import com.fasterxml.jackson.core.JsonFactory import com.fasterxml.jackson.core.JsonFactory
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.jcabi.manifests.Manifests
import net.corda.client.jackson.JacksonSupport import net.corda.client.jackson.JacksonSupport
import net.corda.cliutils.CordaCliWrapper import net.corda.cliutils.CordaCliWrapper
import net.corda.cliutils.ExitCodes import net.corda.cliutils.ExitCodes
@ -16,18 +15,18 @@ import net.corda.core.serialization.internal._contextSerializationEnv
import net.corda.core.utilities.base64ToByteArray import net.corda.core.utilities.base64ToByteArray
import net.corda.core.utilities.hexToByteArray import net.corda.core.utilities.hexToByteArray
import net.corda.core.utilities.sequence import net.corda.core.utilities.sequence
import net.corda.serialization.internal.* import net.corda.serialization.internal.AMQP_P2P_CONTEXT
import net.corda.serialization.internal.AMQP_STORAGE_CONTEXT
import net.corda.serialization.internal.CordaSerializationMagic
import net.corda.serialization.internal.SerializationFactoryImpl
import net.corda.serialization.internal.amqp.AbstractAMQPSerializationScheme import net.corda.serialization.internal.amqp.AbstractAMQPSerializationScheme
import net.corda.serialization.internal.amqp.DeserializationInput import net.corda.serialization.internal.amqp.DeserializationInput
import net.corda.serialization.internal.amqp.amqpMagic import net.corda.serialization.internal.amqp.amqpMagic
import org.slf4j.event.Level
import picocli.CommandLine.* import picocli.CommandLine.*
import java.io.PrintStream import java.io.PrintStream
import java.net.MalformedURLException import java.net.MalformedURLException
import java.net.URL import java.net.URL
import java.nio.file.Paths import java.nio.file.Paths
import java.util.*
import kotlin.system.exitProcess
fun main(args: Array<String>) { fun main(args: Array<String>) {
BlobInspector().start(args) BlobInspector().start(args)
@ -57,6 +56,8 @@ class BlobInspector : CordaCliWrapper("blob-inspector", "Convert AMQP serialised
val bytes = parseToBinaryRelaxed(inputFormatType, inputBytes) val bytes = parseToBinaryRelaxed(inputFormatType, inputBytes)
?: throw IllegalArgumentException("Error: this input does not appear to be encoded in Corda's AMQP extended format, sorry.") ?: throw IllegalArgumentException("Error: this input does not appear to be encoded in Corda's AMQP extended format, sorry.")
initialiseSerialization()
if (schema) { if (schema) {
val envelope = DeserializationInput.getEnvelope(bytes.sequence(), SerializationDefaults.STORAGE_CONTEXT.encodingWhitelist) val envelope = DeserializationInput.getEnvelope(bytes.sequence(), SerializationDefaults.STORAGE_CONTEXT.encodingWhitelist)
out.println(envelope.schema) out.println(envelope.schema)
@ -72,14 +73,13 @@ class BlobInspector : CordaCliWrapper("blob-inspector", "Convert AMQP serialised
val mapper = JacksonSupport.createNonRpcMapper(factory, fullParties) val mapper = JacksonSupport.createNonRpcMapper(factory, fullParties)
initialiseSerialization() return try {
try {
val deserialized = bytes.deserialize<Any>(context = SerializationDefaults.STORAGE_CONTEXT) val deserialized = bytes.deserialize<Any>(context = SerializationDefaults.STORAGE_CONTEXT)
out.println(deserialized.javaClass.name) out.println(deserialized.javaClass.name)
mapper.writeValue(out, deserialized) mapper.writeValue(out, deserialized)
return ExitCodes.SUCCESS ExitCodes.SUCCESS
} catch(e: Exception) { } catch (e: Exception) {
return ExitCodes.FAILURE ExitCodes.FAILURE
} finally { } finally {
_contextSerializationEnv.set(null) _contextSerializationEnv.set(null)
} }
@ -148,15 +148,5 @@ private class SourceConverter : ITypeConverter<URL> {
} }
} }
private class CordaVersionProvider : IVersionProvider {
override fun getVersion(): Array<String> {
return arrayOf(
"Version: ${Manifests.read("Corda-Release-Version")}",
"Revision: ${Manifests.read("Corda-Revision")}"
)
}
}
private enum class OutputFormatType { YAML, JSON } private enum class OutputFormatType { YAML, JSON }
private enum class InputFormatType { BINARY, HEX, BASE64 } private enum class InputFormatType { BINARY, HEX, BASE64 }