printStackTrace() writes an exception to standard error instead of a log
What it finds
e.printStackTrace() goes to standard error, outside the application's logging, where it is easily lost and cannot be filtered or correlated. A logger keeps the failure with the rest of the application's output.
From the rule's source, print_stack_trace.rs.
fun run() { try { work() } catch (e: Exception) { e.printStackTrace()tx0 reports: the exception goes to standard error e.printStackTrace(System.out) }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:print-stack-trace" = "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:print-stack-trace] reason="..."tx0 explain tx0/kotlin:print-stack-trace shows the same in the terminal. Found a false positive? Report it.