Forbid internal classes from being serialised. (#655)

This commit is contained in:
Chris Rankin 2017-05-25 17:18:51 +01:00 committed by GitHub
parent bcf4c4a2bb
commit ea53bab7d7
2 changed files with 6 additions and 1 deletions

View File

@ -472,4 +472,7 @@ fun <T> Class<T>.checkNotUnorderedHashMap() {
if (HashMap::class.java.isAssignableFrom(this) && !LinkedHashMap::class.java.isAssignableFrom(this)) {
throw NotSerializableException("Map type $this is unstable under iteration. Suggested fix: use LinkedHashMap instead.")
}
}
}
fun Class<*>.requireExternal(msg: String = "Internal class")
= require(!name.startsWith("net.corda.node.") && !name.contains(".internal.")) { "$msg: $name" }

View File

@ -5,6 +5,7 @@ package net.corda.nodeapi
import com.esotericsoftware.kryo.Registration
import com.esotericsoftware.kryo.Serializer
import com.google.common.util.concurrent.ListenableFuture
import net.corda.core.requireExternal
import net.corda.core.serialization.*
import net.corda.core.toFuture
import net.corda.core.toObservable
@ -60,6 +61,7 @@ class RPCKryo(observableSerializer: Serializer<Observable<Any>>) : CordaKryo(mak
}
override fun getRegistration(type: Class<*>): Registration {
type.requireExternal("RPC not allowed to deserialise internal classes")
if (Observable::class.java != type && Observable::class.java.isAssignableFrom(type)) {
return super.getRegistration(Observable::class.java)
}