G-4250
🆓Error
Avoid using identical conditions in different branches of the same IF or CASE statement.
Reason
Conditions are evaluated top to bottom in branches of a case
statement or chain of if
/elsif
statements. The first condition to evaluate as true leads to that branch being executed, the rest will never execute. Having an identical duplicated condition in another branch will never be reached and will be dead code.
Example
Non-Compliant Example
declare l_color types_up.color_code_type; begin case l_color when constants_up.co_red then my_package.do_red(); when constants_up.co_blue then my_package.do_blue(); when constants_up.co_red then -- never reached my_package.do_black(); -- dead code else null; end case; end; /
Issues
Line | Column | Message |
---|---|---|
9 | 12 |
★★★★★
Compliant Solution -
declare l_color types_up.color_code_type; begin case l_color when constants_up.co_red then my_package.do_red(); when constants_up.co_blue then my_package.do_blue(); when constants_up.co_black then my_package.do_black(); else null; end case; end; /
References
- same as plsql:S1862
- same as Trivadis G-4250
- similar to plsqlopen:DuplicateConditionIfElsif