CORDA-2848 relax fingerprinter strictness (#5001)

* CORDA-2848 relax fingerprinter strictness

* Unit test for non-serializable type parameter case
This commit is contained in:
Dominic Fox 2019-04-11 15:42:56 +01:00 committed by Rick Parker
parent f9916e673c
commit 2e97eaee0d
2 changed files with 33 additions and 2 deletions

View File

@ -139,8 +139,7 @@ private class FingerPrintingState(
is LocalTypeInformation.Abstract -> fingerprintAbstract(type)
is LocalTypeInformation.Singleton -> fingerprintName(type)
is LocalTypeInformation.Composable -> fingerprintComposable(type)
is LocalTypeInformation.NonComposable -> throw NotSerializableException(
"Attempted to fingerprint non-composable type ${type.typeIdentifier.prettyPrint(false)}")
is LocalTypeInformation.NonComposable -> fingerprintNonComposable(type)
}
}
@ -176,6 +175,14 @@ private class FingerPrintingState(
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) =
fingerprintWithCustomSerializerOrElse(type) {
fingerprintName(type)

View File

@ -1,9 +1,14 @@
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.TypeModellingFingerPrinter
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import kotlin.test.assertNotEquals
import kotlin.test.assertTrue
class TypeModellingFingerPrinterTests {
@ -19,4 +24,23 @@ class TypeModellingFingerPrinterTests {
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)
}
}