mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
CORDA-2782 allow un-whitelisted Comparable (#4940)
This commit is contained in:
parent
dc46446432
commit
c04a448bf3
@ -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.")
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user