...
This noncompliant example differs from the previous one in that, there are no side effects in the right hand side operand. Nevertheless, an unaware programmer can get caught in the short-circuit behavior of the conditional AND and OR operators. The programmer has combined two expressions in the if
statement. The first checks whether the d
object is null
and the second checks if the default security manager has been installed (by comparinf comparing sm
with null
) depending on which the security check will be performed. This is a case of trying to combine together two null
checks into one statement. A conditional &&
is used as using a conditional ||
would mean that whenever d
is null
, the complete expression can still succeed depending on the value of sm
(see the next noncompliant example). This violates the invariants of d
as it is desired that operations on it be prohibited if it is null
.
...