Hello!
I have found an example of unreachable code that is not detected by SonarQube when using switch() on enum types.
For example:
enum SomeEnum {A,B}
void print(SomeEnum e) {
switch(e) {
case A:
//code
break;
case B:
//code
break;
default:
break;
}
}
In this example, the "default" case is unreachable. If SomeEnum.A or SomeEnum.B is passed in, the applicabe case and break will be triggered. If null is passed in, the switch statement will cause a NullPointerException to be thrown.
Since there are no remaining possibilities, the default label and subsequent break are non-reachable and non-testable code and thus should be eliminated.
Thanks,
Brian