An exception is printed to standard error with printStackTrace()

tx0/java:print-stack-tracestrictwarningsmell, cwe-209

What it finds

e.printStackTrace() writes to the standard error stream, which servers and libraries often do not show or keep, and bypasses the logging the program configured. Logging the exception, or passing it on, keeps it where someone will find it.

From the rule's source, print_stack_trace.rs.

Example from the rule's tests
class Worker {  void run() {    try {      step();    } catch (Exception e) {      e.printStackTrace();tx0 reports: the exception is printed to standard error      e.printStackTrace(System.out);    }  }   void step() throws Exception {}}
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/java: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/java:print-stack-trace] reason="..."

tx0 explain tx0/java:print-stack-trace shows the same in the terminal. Found a false positive? Report it.