Throw IllegalArgumentException instead of NumberFormatException on incorrect radix.

This commit is contained in:
Ilya Gorbunov
2016-11-28 18:14:06 +03:00
parent 3c80a7056a
commit 9b421eb7a4
2 changed files with 5 additions and 5 deletions
@@ -283,6 +283,6 @@ private inline fun <T> screenFloatValue(str: String, parse: (String) -> T): T? {
internal fun digitOf(char: Char, radix: Int): Int = Character.digit(char.toInt(), radix)
internal fun checkRadix(radix: Int) {
if(radix !in Character.MIN_RADIX..Character.MAX_RADIX) {
throw NumberFormatException("radix $radix was not in valid range ${Character.MIN_RADIX..Character.MAX_RADIX}")
throw IllegalArgumentException("radix $radix was not in valid range ${Character.MIN_RADIX..Character.MAX_RADIX}")
}
}
@@ -73,8 +73,8 @@ class ParsePrimitivesJVMTest {
assertFailsOrNull(10, "Kona")
}
assertFailsWith<NumberFormatException>("Expected to fail with radix 1") { "1".toInt(radix = 1) }
assertFailsWith<NumberFormatException>("Expected to fail with radix 37") { "37".toIntOrNull(radix = 37) }
assertFailsWith<IllegalArgumentException>("Expected to fail with radix 1") { "1".toInt(radix = 1) }
assertFailsWith<IllegalArgumentException>("Expected to fail with radix 37") { "37".toIntOrNull(radix = 37) }
}
@JvmVersion
@@ -114,8 +114,8 @@ class ParsePrimitivesJVMTest {
assertFailsOrNull(10, "Hazelnut")
}
assertFailsWith<NumberFormatException>("Expected to fail with radix 37") { "37".toLong(radix = 37) }
assertFailsWith<NumberFormatException>("Expected to fail with radix 1") { "1".toLongOrNull(radix = 1) }
assertFailsWith<IllegalArgumentException>("Expected to fail with radix 37") { "37".toLong(radix = 37) }
assertFailsWith<IllegalArgumentException>("Expected to fail with radix 1") { "1".toLongOrNull(radix = 1) }
}
@JvmVersion