Replaced all uses of assert with require (#3309)

JVM assertions have to be enabled with the -ea flag so it's possible for these checks to be ignored.
This commit is contained in:
Shams Asari
2018-06-06 00:31:41 +01:00
committed by GitHub
parent 75f2c4a0a4
commit d620e71bb6
16 changed files with 65 additions and 64 deletions

View File

@ -74,7 +74,7 @@ class ImmutableClassSerializer<T : Any>(val klass: KClass<T>) : Serializer<T>()
init {
// Verify that this class is immutable (all properties are final)
assert(props.none { it is KMutableProperty<*> })
require(props.none { it is KMutableProperty<*> })
}
// Just a utility to help us catch cases where nodes are running out of sync versions.
@ -109,7 +109,7 @@ class ImmutableClassSerializer<T : Any>(val klass: KClass<T>) : Serializer<T>()
}
override fun read(kryo: Kryo, input: Input, type: Class<T>): T {
assert(type.kotlin == klass)
require(type.kotlin == klass)
val numFields = input.readVarInt(true)
val fieldTypeHash = input.readInt()

View File

@ -121,7 +121,7 @@ class RPCSecurityManagerTest {
id = AuthServiceId("TEST"))
val subject = userRealm.buildSubject("foo")
for (action in allActions) {
assert(!subject.isPermitted(action)) {
require(!subject.isPermitted(action)) {
"Invalid subject should not be allowed to call $action"
}
}
@ -143,24 +143,24 @@ class RPCSecurityManagerTest {
for (request in permitted) {
val call = request.first()
val args = request.drop(1).toTypedArray()
assert(subject.isPermitted(request.first(), *args)) {
require(subject.isPermitted(request.first(), *args)) {
"User ${subject.principal} should be permitted $call with target '${request.toList()}'"
}
if (args.isEmpty()) {
assert(subject.isPermitted(request.first(), "XXX")) {
require(subject.isPermitted(request.first(), "XXX")) {
"User ${subject.principal} should be permitted $call with any target"
}
}
}
disabled.forEach {
assert(!subject.isPermitted(it)) {
require(!subject.isPermitted(it)) {
"Permissions $permissions should not allow to call $it"
}
}
disabled.filter { !permitted.contains(listOf(it, "foo")) }.forEach {
assert(!subject.isPermitted(it, "foo")) {
require(!subject.isPermitted(it, "foo")) {
"Permissions $permissions should not allow to call $it with argument 'foo'"
}
}