mirror of
https://github.com/corda/corda.git
synced 2025-02-20 17:33:15 +00:00
CORDA-2266 match old fingerprinter on Any type (#4319)
* CORDA-2266 treat Top differently from Unknown, to match old fingerprinter * Add unit test covering the bug
This commit is contained in:
parent
b51c398ebe
commit
34f581854b
@ -68,7 +68,8 @@ internal class FingerprintWriter(debugEnabled: Boolean) {
|
||||
fun writeArray() = append(ARRAY_HASH)
|
||||
fun writeNullable() = append(NULLABLE_HASH)
|
||||
fun writeNotNullable() = append(NOT_NULLABLE_HASH)
|
||||
fun writeAny() = append(ANY_TYPE_HASH)
|
||||
fun writeUnknown() = append(ANY_TYPE_HASH)
|
||||
fun writeTop() = append(Any::class.java.name)
|
||||
|
||||
private fun append(chars: CharSequence) = apply {
|
||||
debugBuffer?.append(chars)
|
||||
@ -123,8 +124,8 @@ private class FingerPrintingState(
|
||||
when (type) {
|
||||
is LocalTypeInformation.Cycle ->
|
||||
throw IllegalStateException("Cyclic references must be dereferenced before fingerprinting")
|
||||
is LocalTypeInformation.Unknown,
|
||||
is LocalTypeInformation.Top -> writer.writeAny()
|
||||
is LocalTypeInformation.Unknown -> writer.writeUnknown()
|
||||
is LocalTypeInformation.Top -> writer.writeTop()
|
||||
is LocalTypeInformation.AnArray -> {
|
||||
fingerprintType(type.componentType)
|
||||
writer.writeArray()
|
||||
@ -204,7 +205,7 @@ private class FingerPrintingState(
|
||||
|
||||
// Compensate for the serialisation framework's forcing of char to Character
|
||||
private fun adjustType(propertyType: LocalTypeInformation): Pair<Boolean, LocalTypeInformation> =
|
||||
if (propertyType.typeIdentifier.name == "char") true to CHARACTER_TYPE else false to propertyType
|
||||
if (propertyType.typeIdentifier.name == "char") true to CHARACTER_TYPE else false to propertyType
|
||||
|
||||
private fun fingerprintInterfaces(interfaces: List<LocalTypeInformation>) =
|
||||
interfaces.forEach { fingerprintType(it) }
|
||||
|
@ -0,0 +1,22 @@
|
||||
package net.corda.serialization.internal.amqp
|
||||
|
||||
import net.corda.serialization.internal.model.LocalTypeInformation
|
||||
import net.corda.serialization.internal.model.TypeModellingFingerPrinter
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
class TypeModellingFingerPrinterTests {
|
||||
|
||||
val descriptorBasedSerializerRegistry = DefaultDescriptorBasedSerializerRegistry()
|
||||
val customRegistry = CachingCustomSerializerRegistry(descriptorBasedSerializerRegistry)
|
||||
val fingerprinter = TypeModellingFingerPrinter(customRegistry, true)
|
||||
|
||||
// See https://r3-cev.atlassian.net/browse/CORDA-2266
|
||||
@Test
|
||||
fun `Object and wildcard are fingerprinted differently`() {
|
||||
val objectType = LocalTypeInformation.Top
|
||||
val anyType = LocalTypeInformation.Unknown
|
||||
|
||||
assertNotEquals(fingerprinter.fingerprint(objectType), fingerprinter.fingerprint(anyType))
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user