-
Type:
Bug Detection
-
Status: Active
-
Resolution: Unresolved
-
Message:This [branch|case] duplicates the one on line n.
-
Highlighting:
-
Default Severity:Major
-
Impact:Low
-
Likelihood:High
-
Default Quality Profiles:Sonar way
-
Targeted languages:Flex, PL/I, VB6
-
Covered Languages:ABAP, C#, C, C++, Cobol, Go, Java, JavaScript, Kotlin, Objective-C, PHP, PL/SQL, Python, RPG, Ruby, Scala, Swift, T-SQL, TypeScript, VB.Net
-
Irrelevant for Languages:HTML, XML
-
Remediation Function:Constant/Issue
-
Constant Cost:10min
-
Analysis Level:Syntactic Analysis
-
Analysis Scope:Main Sources, Test Sources
-
Common Rule:Yes
-
CERT:MSC12-C.
-
CPPCheck:duplicateIf, multiCondition
-
ESLint:no-duplicate-case
-
ESLint-SonarJS:no-identical-conditions
-
PC-Lint:137, 1137, 142, 1142
-
PVS-Studio:V3003
-
TSLint-SonarTS:no-identical-conditions
A chain of if/else if statements is evaluated from top to bottom. At most, only one branch will be executed: the first one with a condition that evaluates to true.
Therefore, duplicating a condition automatically leads to dead code. Usually, this is due to a copy/paste error. At best, it's simply dead code and at worst, it's a bug that is likely to induce further bugs as the code is maintained, and obviously it could lead to unexpected behavior.
See
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- contributes to
-
MMF-887 First pack of Typescript rules available as a TSLint extension
-
- Closed
-
- deprecates
-
RSPEC-1950 Cases in a "switch" should not have the same condition
- Deprecated
- is implemented by
-
SONARFLEX-71 Rule S1862: Related "if/else if" statements and "cases" in a "switch" should not have the same condition
-
- Open
-
-
SONARPLI-180 Rule: Related "if/else if" statements should not have the same condition
-
- Open
-
-
SONARVBSIX-260 Rule: Related "if/else if" statements should not have the same condition
-
- Open
-
-
CPP-709 Rule: Duplicate conditions in "if" and related "else if"
-
- Closed
-
-
SONARCOBOL-1188 Rule: Conditions in related "IF/ELSE IF" statements and "WHEN" clauses in "EVALUATE" statements should not have the same condition
-
- Closed
-
-
SONARFLEX-66 Rule: Related "if/else if" statements and "cases" in a "switch" should not have the same condition
-
- Closed
-
-
SONARPHP-430 Rule: Related "if/else if" statements and "cases" in a "[switch|Select Case]" should not have the same condition
-
- Closed
-
-
SONARPLSQL-600 Rule: Related "IF/ELSIF" statements and "WHEN" clauses in a "CASE" should not have the same condition
-
- Closed
-
-
SONARRPG-116 Rule: Related "IF/ELSEIF" statements and "WHEN" clauses in a "SELECT" should not have the same condition
-
- Closed
-
-
SONARSLANG-155 Enable in Ruby rule S1862 (IdenticalConditionsCheck)
-
- Closed
-
-
SONARSLANG-218 [Scala] Enable Rule: S1862 Related "if/else if" statements should not have the same condition
-
- Closed
-
-
SONARSLANG-322 [Apex] Enable Rule: S1862 Related "if/else if" statements should not have the same condition
-
- Closed
-
-
SONARSWIFT-60 Rule: Conditions in related "if/else if" statements and "cases" in a "switch" should not have the same condition
-
- Closed
-
-
SONARTSQL-15 Rule: Related "IF"/"ELSE IF" statements and "WHEN" clauses in a "CASE" should not have the same condition
-
- Closed
-
-
CPP-707 Create Objective-C rules repository containing targeted rules
-
- Closed
-
-
SONARSLANG-426 [Go] Enable rules relying on Conditions
-
- Closed
-
- is related to
-
CPP-2510 S3923: Improve code equivalence checking in case of macro expansion
-
- Open
-
-
RSPEC-1763 All code should be reachable
- Active
-
RSPEC-901 Dead code should be removed
- Closed
-
RSPEC-2760 Sequential tests should not check the same condition
- Active
- relates to
-
SONARPHP-1086 S1862: Add a message on the secondary location
-
- Closed
-
- links to