An if throws IllegalArgumentException or IllegalStateException, which require and check say directly
What it finds
if (count < 0) throw IllegalArgumentException("negative") is require(count >= 0) { "negative" }, and the same with IllegalStateException is check. The standard functions state the condition that must hold, and the compiler uses them for smart casts.
From the rule's source, throw_instead_of_require.rs.
fun withdraw(amount: Int, open: Boolean) { if (amount < 0) throw IllegalArgumentException("negative")tx0 reports: this if and throw say require if (!open) {tx0 reports: say check throw IllegalStateException("closed") } if (amount > 10) throw UnsupportedOperationException()} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:throw-instead-of-require" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/kotlin:throw-instead-of-require] reason="..."tx0 explain tx0/kotlin:throw-instead-of-require shows the same in the terminal. Found a false positive? Report it.