mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
Fingerprint for Exception class reverted to V3 (fixes CORDA-2227 & CORDA-2292) (#4386)
This commit is contained in:
parent
c31da13c70
commit
b020e602ba
@ -65,17 +65,25 @@ abstract class CustomSerializer<T : Any> : AMQPSerializer<T>, SerializerFor {
|
||||
override val schemaForDocumentation = Schema(emptyList())
|
||||
|
||||
override fun isSerializerFor(clazz: Class<*>): Boolean = clazz == this.clazz
|
||||
|
||||
override val type: Type get() = clazz
|
||||
|
||||
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(
|
||||
AMQPTypeIdentifiers.nameForType(clazz),
|
||||
null,
|
||||
emptyList(),
|
||||
AMQPTypeIdentifiers.nameForType(superClassSerializer.type),
|
||||
Descriptor(typeDescriptor),
|
||||
emptyList())
|
||||
emptyList()
|
||||
)
|
||||
|
||||
override fun writeClassInfo(output: SerializationOutput) {
|
||||
output.writeTypeNotations(typeNotation)
|
||||
|
@ -45,7 +45,7 @@ class TypeModellingFingerPrinter(
|
||||
* Wrapper for the [Hasher] we use to generate fingerprints, providing methods for writing various kinds of content
|
||||
* into the hash.
|
||||
*/
|
||||
internal class FingerprintWriter(debugEnabled: Boolean) {
|
||||
internal class FingerprintWriter(debugEnabled: Boolean = false) {
|
||||
|
||||
companion object {
|
||||
private const val ARRAY_HASH: String = "Array = true"
|
||||
|
@ -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==")
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package net.corda.blobinspector
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
|
||||
import com.jcabi.manifests.Manifests
|
||||
import net.corda.client.jackson.JacksonSupport
|
||||
import net.corda.cliutils.CordaCliWrapper
|
||||
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.hexToByteArray
|
||||
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.DeserializationInput
|
||||
import net.corda.serialization.internal.amqp.amqpMagic
|
||||
import org.slf4j.event.Level
|
||||
import picocli.CommandLine.*
|
||||
import java.io.PrintStream
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
BlobInspector().start(args)
|
||||
@ -57,6 +56,8 @@ class BlobInspector : CordaCliWrapper("blob-inspector", "Convert AMQP serialised
|
||||
val bytes = parseToBinaryRelaxed(inputFormatType, inputBytes)
|
||||
?: throw IllegalArgumentException("Error: this input does not appear to be encoded in Corda's AMQP extended format, sorry.")
|
||||
|
||||
initialiseSerialization()
|
||||
|
||||
if (schema) {
|
||||
val envelope = DeserializationInput.getEnvelope(bytes.sequence(), SerializationDefaults.STORAGE_CONTEXT.encodingWhitelist)
|
||||
out.println(envelope.schema)
|
||||
@ -72,14 +73,13 @@ class BlobInspector : CordaCliWrapper("blob-inspector", "Convert AMQP serialised
|
||||
|
||||
val mapper = JacksonSupport.createNonRpcMapper(factory, fullParties)
|
||||
|
||||
initialiseSerialization()
|
||||
try {
|
||||
return try {
|
||||
val deserialized = bytes.deserialize<Any>(context = SerializationDefaults.STORAGE_CONTEXT)
|
||||
out.println(deserialized.javaClass.name)
|
||||
mapper.writeValue(out, deserialized)
|
||||
return ExitCodes.SUCCESS
|
||||
} catch(e: Exception) {
|
||||
return ExitCodes.FAILURE
|
||||
ExitCodes.SUCCESS
|
||||
} catch (e: Exception) {
|
||||
ExitCodes.FAILURE
|
||||
} finally {
|
||||
_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 InputFormatType { BINARY, HEX, BASE64 }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user