ABSTRACT

This expression (or part of it) will always evaluate to false.

EXPLANATION

This expression (or part of it) will always evaluate to false; the program could be rewritten in a simpler form. The nearby code may be present for debugging purposes, or it may not have been maintained along with the rest of the program. The expression may also be indicative of a bug earlier in the method.

Example 1: The following method never sets the variable secondCall after initializing it to false. (The variable firstCall is mistakenly used twice.) The result is that the expression firstCall && secondCall will always evaluate to false, so setUpDualCall() will never be invoked.


public void setUpCalls() {
boolean firstCall = false;
boolean secondCall = false;

if (fCall > 0) {
setUpFCall();
firstCall = true;
}
if (sCall > 0) {
setUpSCall();
firstCall = true;
}

if (firstCall && secondCall) {
setUpDualCall();
}
}


Example 2: The following method never sets the variable firstCall to false. (The variable firstCall is mistakenly set to false after the first conditional statement.) The result is that the first part of the expression firstCall && secondCall will always evaluate to false.


public void setUpCalls() {
boolean firstCall = false;
boolean secondCall = false;

if (fCall > 0) {
setUpFCall();
firstCall = false;
}
if (sCall > 0) {
setUpSCall();
secondCall = true;
}

if (firstCall || secondCall) {
setUpForCall();
}
}


REFERENCES

[1] Standards Mapping - Security Technical Implementation Guide Version 3 - (STIG 3) APP3050 CAT II

[2] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 570