A switch is nested inside another switch

tx0/java:nested-switchstrictwarningstyle

What it finds

A switch inside a case of another switch makes both hard to read: the cases of the inner one look like those of the outer one, and a break in it only leaves the inner one. A method for the inner switch keeps them apart.

A switch statement or expression is reported when another one contains it, unless a lambda or class body lies between them.

From the rule's source, nested_switch.rs.

Example from the rule's tests
class Router {  void route(int a, int b) {    switch (a) {      case 1:        switch (b) {tx0 reports: this switch is nested inside another switch          case 2:            break;        }        break;      default:        Runnable r = () -> {          switch (b) {            default:          }        };    }  }}
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:nested-switch" = "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:nested-switch] reason="..."

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