A catch catches an exception that signals a bug, such as NullPointerException

tx0/kotlin:catch-programming-errorstrictwarningreliability/error-handlingdepth fastsmell

What it finds

NullPointerException, ClassCastException, IndexOutOfBoundsException and ConcurrentModificationException say that the code is wrong, not that the world is. Catching them hides the bug; checking for the condition before it happens fixes it.

From the rule's source, catch_programming_error.rs.

Example from the rule's tests
fun first(items: List<String>): String? {    try {        return items[0].trim()    } catch (e: IndexOutOfBoundsException) {tx0 reports: catching IndexOutOfBoundsException hides a bug        return null    } catch (e: NullPointerException) {tx0 reports: catching NullPointerException hides a bug        return null    } catch (e: IllegalStateException) {        return null    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/kotlin:catch-programming-error" = "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:catch-programming-error] reason="..."

tx0 explain tx0/kotlin:catch-programming-error shows the same in the terminal. Found a false positive? Report it.