Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2583

Conditionally executed code should be reachable

    XMLWordPrintable

    Details

    • Message:
      Change this condition so that it does not always evaluate to "[true|false]"; some subsequent code is never executed.
    • Highlighting:
      Hide

      Primary: condition which always evaluates to the same value

      • Secondary:
        • Parts of code which are never reached with message "Never reached"
      • Flow
        • The last locations in the code leading to know something on each variable part of the condition.
      Show
      Primary: condition which always evaluates to the same value Secondary: Parts of code which are never reached with message "Never reached" Flow The last locations in the code leading to know something on each variable part of the condition.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      ABAP, Flex, Go, Kotlin, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Ruby, Scala, Swift, T-SQL, TypeScript, VB.Net, VB6
    • Covered Languages:
      C#, C, C++, Cobol, Java, JavaScript
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      15min
    • Analysis Level:
      Control-flow Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Implementation details:
    • Common Rule:
      Yes
    • CERT:
      MSC12-C.
    • CWE:
      CWE-489, CWE-571, CWE-570
    • CPPCheck:
      assignIfError, comparisonError, incorrectLogicOperator, moduloAlwaysTrueFalse, oppositeInnerCondition, incorrectStringBooleanError, unsignedLessThanZero, unsignedPositive, secondAlwaysTrueFalseWhenFirstTrue, redundantCondition
    • ESLint:
      no-constant-condition, no-self-compare, no-unsafe-negation
    • FindBugs:
      BIT_AND, BIT_AND_ZZ, BIT_IOR, BIT_SIGNED_CHECK, BIT_SIGNED_CHECK_HIGH_BIT, UC_USELESS_CONDITION, UC_USELESS_CONDITION_TYPE, RCN_REDUNDANT.*
    • FxCop:
      CA1508
    • PC-Lint:
      506, 1506, 587, 1587, 588, 1588, 589, 1589, 590, 1590, 685, 1685, 774, 1774, 944, 1944, 948, 1948, 568, 1568, 775, 1775
    • PMD:
      UnconditionalIfStatement
    • ReSharper:
      ConditionIsAlwaysTrueOrFalse

      Description

      Conditional expressions which are always true or false can lead to dead code. Such code is always buggy and should never be used in production.

      Noncompliant Code Example

      a = false;
      if (a) { // Noncompliant
        doSomething(); // never executed
      }
      
      if (!a || b) { // Noncompliant; "!a" is always "true", "b" is never evaluated
        doSomething();
      } else {
        doSomethingElse(); // never executed
      }
      

      See

        Attachments

          Issue Links

          1.
          COBOL RSPEC-3953 Language-Specification Active Unassigned
          2.
          C# RSPEC-3969 Language-Specification Active Unassigned
          3.
          JavaScript RSPEC-3975 Language-Specification Active Unassigned
          4.
          C-Family RSPEC-4271 Language-Specification Active Unassigned
          5.
          Java RSPEC-4272 Language-Specification Active Unassigned
          6.
          Python RSPEC-5623 Language-Specification Active Unassigned

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              pierre-yves.nicolas Pierre-Yves Nicolas
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: