Two catch clauses of one try have the same body and could be one multi-catch

tx0/java:mergeable-catchesstrictwarningstyle

What it finds

catch (IOException e) { fail(e); } catch (SQLException e) { fail(e); } repeats the handler; catch (IOException | SQLException e) states once what both do, and a later change cannot reach only one of them.

Reported is a catch clause whose block is the same as that of an earlier clause of the same try.

From the rule's source, mergeable_catches.rs.

Example from the rule's tests
import java.io.IOException;import java.sql.SQLException; class Io {  void run() {    try {      work();    } catch (IOException e) {      fail(e);    } catch (SQLException e) {tx0 reports: repeats an earlier one      fail(e);    } catch (Exception e) {      System.out.println(e);    }  }   void work() throws Exception {}   void fail(Exception e) {}}
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:mergeable-catches" = "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:mergeable-catches] reason="..."

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