Using Java, SonarQube is complaining about switch statements on enum values not having a default:
case.
The reasoning given is:
"The requirement for a final default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken. When the switch covers all current values of an enum - and especially when it doesn't - a default case should still be used because there is no guarantee that the enum won't be extended."
I do not agree with the above statements - I want the following behavior to generate a warning:
- Modifying an enum so that the switch no longer covers every case.
By requiring a default case - we will not get a warning if the enum changes, and the switch will no longer handles all the cases.