& logical operators, known as non-short circuit
operators, should not be used. Using a non-short circuit operator reduces the efficiency of the
program, is potentially confusing and can even lead to the program crashing if the first operand
acts as a safety check for the second.
If the non-short circuit operator is unintended then replace the operator with the short circuit equivalent. Sometime a non-short circuit operator is required because the operands have side effects. In this case it is more efficient to evaluate both operands separately and then use a short circuit operator to combine the results.
This example will crash because both parts of the conditional expression will be evaluated even
a is null.
The example is easily fixed by using the short circuit AND operator. The program produces no output but does not crash, unlike the previous example.