Throw IllegalArgumentException instead of NumberFormatException on incorrect radix.
This commit is contained in:
@@ -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 digitOf(char: Char, radix: Int): Int = Character.digit(char.toInt(), radix)
|
||||||
internal fun checkRadix(radix: Int) {
|
internal fun checkRadix(radix: Int) {
|
||||||
if(radix !in Character.MIN_RADIX..Character.MAX_RADIX) {
|
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")
|
assertFailsOrNull(10, "Kona")
|
||||||
}
|
}
|
||||||
|
|
||||||
assertFailsWith<NumberFormatException>("Expected to fail with radix 1") { "1".toInt(radix = 1) }
|
assertFailsWith<IllegalArgumentException>("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 37") { "37".toIntOrNull(radix = 37) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmVersion
|
@JvmVersion
|
||||||
@@ -114,8 +114,8 @@ class ParsePrimitivesJVMTest {
|
|||||||
assertFailsOrNull(10, "Hazelnut")
|
assertFailsOrNull(10, "Hazelnut")
|
||||||
}
|
}
|
||||||
|
|
||||||
assertFailsWith<NumberFormatException>("Expected to fail with radix 37") { "37".toLong(radix = 37) }
|
assertFailsWith<IllegalArgumentException>("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 1") { "1".toLongOrNull(radix = 1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmVersion
|
@JvmVersion
|
||||||
|
|||||||
Reference in New Issue
Block a user