CORDA-2782 allow un-whitelisted Comparable (#4940)

This commit is contained in:
Dominic Fox 2019-03-29 15:24:08 +00:00 committed by josecoll
parent dc46446432
commit c04a448bf3
2 changed files with 31 additions and 3 deletions

View File

@ -122,10 +122,9 @@ internal enum class CommonPropertyNames {
IncludeInternalInfo,
}
fun ClassWhitelist.requireWhitelisted(type: Type) {
if (!this.isWhitelisted(type.asClass())) {
// See CORDA-2782 for explanation of the special exemption made for Comparable
if (!this.isWhitelisted(type.asClass()) && type.asClass() != java.lang.Comparable::class.java) {
throw AMQPNotSerializableException(
type,
"Class \"$type\" is not on the whitelist or annotated with @CordaSerializable.")

View File

@ -583,6 +583,35 @@ class DeserializeSimpleTypesTests {
}
}
// See CORDA-2782
@Test
fun comparableNotWhitelistedOk() {
@CordaSerializable
class Ok(val value: String) : java.lang.Comparable<Ok> {
override fun compareTo(o: Ok?): Int = value.compareTo(o?.value ?: "")
}
class NotOk(val value: String) : java.lang.Comparable<NotOk> {
override fun compareTo(o: NotOk?): Int = value.compareTo(o?.value ?: "")
}
@CordaSerializable
class OkComparable(val value: java.lang.Comparable<Ok>)
@CordaSerializable
class NotOkComparable(val value: java.lang.Comparable<NotOk>)
val factory = testDefaultFactoryWithWhitelist()
TestSerializationOutput(VERBOSE, factory).serialize(OkComparable(Ok("value")))
assertFailsWithMessage(
"Class \"class ${NotOk::class.java.name}\" " +
"is not on the whitelist or annotated with @CordaSerializable.") {
TestSerializationOutput(VERBOSE, factory).serialize(NotOkComparable(NotOk("value")))
}
}
private fun assertFailsWithMessage(expectedMessage: String, block: () -> Unit) {
try {
block()