-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Message:Add a "[case default|WHEN OTHERS|Case Else]" clause to this "[switch|CASE|Select]" statement.
-
Default Severity:Critical
-
Impact:High
-
Likelihood:Low
-
Default Quality Profiles:Sonar way
-
Legacy Key:switch-without-default, SwitchWithoutDefault, SwitchLastCaseIsDefaultCheck, SelectWithoutCaseElse, SelectWithoutOtherwise, COBOL.EvaluateStatementUsageCheck
-
Targeted languages:RPG, TypeScript
-
Covered Languages:ABAP, C#, C, C++, Cobol, Flex, Go, Java, JavaScript, Objective-C, PHP, PL/I, PL/SQL, Ruby, T-SQL, VB.Net, VB6
-
Irrelevant for Languages:HTML, Kotlin, Python, Swift, XML
-
Remediation Function:Constant/Issue
-
Constant Cost:5min
-
Analysis Level:Syntactic Analysis
-
Analysis Scope:Main Sources, Test Sources
-
Common Rule:Yes
-
CERT:MSC01-C.
-
CWE:CWE-478
-
Checkstyle:DefaultComesLast, MissingSwitchDefault
-
ESLint:default-case
-
FindBugs:SF_SWITCH_NO_DEFAULT
-
PC-Lint:744, 1744, 9014, 9082
-
PMD:DefaultLabelNotLastInSwitchStmt,SwitchStmtsShouldHaveDefault
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.
See
- MITRE, CWE-478 - Missing Default Case in Switch Statement
- CERT, MSC01-C. - Strive for logical completeness
- duplicates
-
RSPEC-915 A switch statement shall be a well-formed switch statement
- Closed
- is duplicated by
-
RSPEC-918 The final clause of a switch statement shall be the default clause
- Closed
- is implemented by
-
SONARRPG-160 Rule S131: "switch" statements should have "default" clauses
-
- Open
-
-
SONARSLANG-229 [Scala] Enable Rule: S131 "match" statements should have "case _" clauses
-
- Open
-
-
SONARPLI-28 Rule : Avoid SELECT statement without the OTHERWISE clause
-
- Closed
-
-
SONARPLSQL-669 Rule S131: "switch" statements should have "default" clauses
-
- Closed
-
-
SONARSLANG-76 Rule S131: "switch" statements should have "default" clauses
-
- Closed
-
-
SONARSLANG-312 [Apex] Enable Rule: S131 "switch" statements should have "default" clauses
-
- Closed
-
-
SONARSWIFT-348 Rule S131: "switch" statements should have "default" clauses
-
- Closed
-
-
SONARTSQL-25 Rule: "CASE" expressions should end with "ELSE" clauses
-
- Closed
-
-
SONARVBSIX-177 Rule: "[switch|CASE]" statements should end with a "[case default|WHEN OTHERS|Case Else]" clause
-
- Closed
-
-
CPP-707 Create Objective-C rules repository containing targeted rules
-
- Closed
-
-
CPP-2003 Adjust the behavior of S131 to not raise an issue when "default" is not at the correct position
-
- Closed
-
-
SONARABAP-211 Update title and description of rule "Missing OTHERS in CASE"
-
- Closed
-
-
SONARABAP-369 Improve S131: exclude cases when "default" is not last
-
- Closed
-
-
SONARCOBOL-1510 Adjust the behavior of S131 to not raise an issue when "default" is not at the correct position
-
- Closed
-
-
SONARFLEX-150 SwitchWithoutDefault(S131): Do not raise an issue when "default" is not at last position
-
- Closed
-
-
SONARJAVA-2700 Adjust the behavior of S131 to not raise an issue when "default" is not at the correct position
-
- Closed
-
-
SONARPHP-784 Adjust the behavior of S131 to not raise an issue when "default" is not at the correct position
-
- Closed
-
-
SONARPLI-192 Adjust the behavior of S131 to not raise an issue when "default" is not at the correct position
-
- Closed
-
-
SONARTSQL-128 Adjust the behavior of S131 to not raise an issue when "default" is not at the correct position
-
- Closed
-
-
SONARVB-305 Adjust the behavior of S131 to not raise an issue when "default" is not at the correct position
-
- Closed
-
-
SONARVBSIX-276 S131: Do not raise an issue when "default" is not at the correct position
-
- Closed
-
- is related to
-
RSPEC-3532 Empty "default" clauses should be removed
- Active
-
RSPEC-3562 "switch" statements should cover all cases
- Active
- relates to
-
CPP-2768 S131, S2816: Accept the "default:"-less exhaustive "switch"es for the SonarWay version of S2816(S131)
-
- Open
-
-
CPP-2766 S131: Use "double quotes" for the code in the message
-
- Closed
-
-
RSPEC-3458 Empty "case" clauses that fall through to the "default" should be omitted
- Active
- links to