- What language is this for?
Java - Which rule?
java:S131 - Why do you believe it’s a false-positive/false-negative?
- Are you using
- SonarQube Cloud?
- SonarQube Server / Community Build - which version?
- SonarQube for IDE - which IDE/version?
- in connected mode with SonarQube Server / Community Build or SonarQube Cloud?
Developer Edition v10.5.1 (90531)
- in connected mode with SonarQube Server / Community Build or SonarQube Cloud?
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
An exhaustive switch statement over an enum might look like this:
class Scratch {
enum SomeEnum {
OPEN,
CLOSED,
ON_HOLD
}
public static void main(String[] args) {
SomeEnum status = SomeEnum.CLOSED;
switch(status) {
case CLOSED -> System.out.println("Not Open");
case ON_HOLD -> System.out.println("Not Open");
case OPEN -> System.out.println("Open");
}
}
}
In this example, the code called for both the CLOSED and ON_HOLD labels is the same, so naturally one wants to condense the switch statement:
switch(status) {
case CLOSED, ON_HOLD -> System.out.println("Not Open");
case OPEN -> System.out.println("Open");
}
In this example, rule java:S131 falsely reports that this switch statement should have a default case. SonarLint plugin for IntelliJ v10.12.0.79769 Does not report on this example.