mirror of
https://github.com/corda/corda.git
synced 2025-05-07 11:08:40 +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,
|
IncludeInternalInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fun ClassWhitelist.requireWhitelisted(type: Type) {
|
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(
|
throw AMQPNotSerializableException(
|
||||||
type,
|
type,
|
||||||
"Class \"$type\" is not on the whitelist or annotated with @CordaSerializable.")
|
"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) {
|
private fun assertFailsWithMessage(expectedMessage: String, block: () -> Unit) {
|
||||||
try {
|
try {
|
||||||
block()
|
block()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user