mirror of
https://github.com/corda/corda.git
synced 2024-12-20 05:28:21 +00:00
CORDA-2848 relax fingerprinter strictness (#5001)
* CORDA-2848 relax fingerprinter strictness * Unit test for non-serializable type parameter case
This commit is contained in:
parent
f9916e673c
commit
2e97eaee0d
@ -139,8 +139,7 @@ private class FingerPrintingState(
|
|||||||
is LocalTypeInformation.Abstract -> fingerprintAbstract(type)
|
is LocalTypeInformation.Abstract -> fingerprintAbstract(type)
|
||||||
is LocalTypeInformation.Singleton -> fingerprintName(type)
|
is LocalTypeInformation.Singleton -> fingerprintName(type)
|
||||||
is LocalTypeInformation.Composable -> fingerprintComposable(type)
|
is LocalTypeInformation.Composable -> fingerprintComposable(type)
|
||||||
is LocalTypeInformation.NonComposable -> throw NotSerializableException(
|
is LocalTypeInformation.NonComposable -> fingerprintNonComposable(type)
|
||||||
"Attempted to fingerprint non-composable type ${type.typeIdentifier.prettyPrint(false)}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,6 +175,14 @@ private class FingerPrintingState(
|
|||||||
fingerprintTypeParameters(type.typeParameters)
|
fingerprintTypeParameters(type.typeParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fingerprintNonComposable(type: LocalTypeInformation.NonComposable) =
|
||||||
|
fingerprintWithCustomSerializerOrElse(type) {
|
||||||
|
fingerprintName(type)
|
||||||
|
fingerprintProperties(type.properties)
|
||||||
|
fingerprintInterfaces(type.interfaces)
|
||||||
|
fingerprintTypeParameters(type.typeParameters)
|
||||||
|
}
|
||||||
|
|
||||||
private fun fingerprintComposable(type: LocalTypeInformation.Composable) =
|
private fun fingerprintComposable(type: LocalTypeInformation.Composable) =
|
||||||
fingerprintWithCustomSerializerOrElse(type) {
|
fingerprintWithCustomSerializerOrElse(type) {
|
||||||
fingerprintName(type)
|
fingerprintName(type)
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
package net.corda.serialization.internal.amqp
|
package net.corda.serialization.internal.amqp
|
||||||
|
|
||||||
|
import net.corda.serialization.internal.AllWhitelist
|
||||||
|
import net.corda.serialization.internal.NotSerializable
|
||||||
|
import net.corda.serialization.internal.model.ConfigurableLocalTypeModel
|
||||||
import net.corda.serialization.internal.model.LocalTypeInformation
|
import net.corda.serialization.internal.model.LocalTypeInformation
|
||||||
import net.corda.serialization.internal.model.TypeModellingFingerPrinter
|
import net.corda.serialization.internal.model.TypeModellingFingerPrinter
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import kotlin.test.assertNotEquals
|
import kotlin.test.assertNotEquals
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class TypeModellingFingerPrinterTests {
|
class TypeModellingFingerPrinterTests {
|
||||||
|
|
||||||
@ -19,4 +24,23 @@ class TypeModellingFingerPrinterTests {
|
|||||||
|
|
||||||
assertNotEquals(fingerprinter.fingerprint(objectType), fingerprinter.fingerprint(anyType))
|
assertNotEquals(fingerprinter.fingerprint(objectType), fingerprinter.fingerprint(anyType))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not serializable, because there is no readable property corresponding to the constructor parameter
|
||||||
|
class NonSerializable(a: String)
|
||||||
|
|
||||||
|
class HasTypeParameter<T>
|
||||||
|
data class SuppliesTypeParameter(val value: HasTypeParameter<NonSerializable>)
|
||||||
|
|
||||||
|
// See https://r3-cev.atlassian.net/browse/CORDA-2848
|
||||||
|
@Test
|
||||||
|
fun `can fingerprint type with non-serializable type parameter`() {
|
||||||
|
val typeModel = ConfigurableLocalTypeModel(WhitelistBasedTypeModelConfiguration(AllWhitelist, customRegistry))
|
||||||
|
val typeInfo = typeModel.inspect(SuppliesTypeParameter::class.java)
|
||||||
|
|
||||||
|
assertThat(typeInfo).isInstanceOf(LocalTypeInformation.Composable::class.java)
|
||||||
|
val propertyTypeInfo = typeInfo.propertiesOrEmptyMap["value"]?.type as LocalTypeInformation.Composable
|
||||||
|
assertThat(propertyTypeInfo.typeParameters[0]).isInstanceOf(LocalTypeInformation.NonComposable::class.java)
|
||||||
|
|
||||||
|
fingerprinter.fingerprint(typeInfo)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user