Minimum 'switch' branches
switch statements and expressions with too few
case labels, and suggests rewriting them as
else if statements.
Example (minimum branches == 3):
After the quick-fix is applied:
Exhaustive switch expressions (Java 14+) or pattern switch statements (Java 17 preview) without the 'default' branch are not reported. That's because compile-time exhaustiveness check will be lost when the
switch is converted to
if which might be undesired.
Configure the inspection:
Use the Minimum number of branches field to specify the minimum expected number of
Use the Do not report pattern switch statements option to avoid reporting switch statements and expressions that have pattern branches. E.g.:
It might be preferred to keep the switch even with a single pattern branch, rather than using the
Minimum number of branches
Do not report pattern switch statements
IntelliJ IDEA 2023.3, Qodana for JVM 2023.3