1
0
mirror of https://github.com/square/okhttp.git synced 2025-08-01 16:06:56 +03:00

Use check/require instead of if/throw

This commit is contained in:
Jesse Wilson
2019-05-20 18:08:58 -04:00
parent 0718352c4e
commit 2c59337e31
10 changed files with 30 additions and 52 deletions

View File

@ -47,9 +47,7 @@ object DnsRecordCodec {
val labels = host.split('.').dropLastWhile { it.isEmpty() }
for (label in labels) {
val utf8ByteCount = label.utf8Size()
if (utf8ByteCount != label.length.toLong()) {
throw IllegalArgumentException("non-ascii hostname: $host")
}
require(utf8ByteCount == label.length.toLong()) { "non-ascii hostname: $host" }
nameBuf.writeByte(utf8ByteCount.toInt())
nameBuf.writeUtf8(label)
}
@ -69,9 +67,7 @@ object DnsRecordCodec {
buf.readShort() // query id
val flags = buf.readShort().toInt() and 0xffff
if (flags shr 15 == 0) {
throw IllegalArgumentException("not a response")
}
require(flags shr 15 != 0) { "not a response" }
val responseCode = flags and 0xf