A catch catches an exception that signals a bug, such as NullPointerException
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.
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 }} 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: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.