A method declares throws Exception or throws Throwable

tx0/java:generic-throwsstrictwarningsmell, cwe-397

What it finds

void load() throws Exception tells callers that anything may go wrong, and makes them catch or declare every checked exception, so that they cannot handle the failures that actually happen on their own.

Methods annotated with @Override take their signature from the method they override, and main is left alone.

From the rule's source, generic_throws.rs.

Example from the rule's tests
class Service implements AutoCloseable {  void load() throws Exception {tx0 reports: the method declares the generic Exception  }   void save() throws java.io.IOException {  }   @Override  public void close() throws Exception {  }   public static void main(String[] args) 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:generic-throws" = "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:generic-throws] reason="..."

tx0 explain tx0/java:generic-throws shows the same in the terminal. Found a false positive? Report it.