Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This code can fail as a result of the same errors it is attempting trying to prevent. When array is NULL or when or i is not a valid index, the reference to array[i] will cause either a NullPointerException or an ArrayIndexOutOfBoundsException to be thrown. This happens because the & operator fails to prevent evaluation of its right operand even when evaluation of its left operand proves that the right operand is invalid.

...

Nevertheless, this solution is preferable when the error-handling code for each potential failure condition failure is different.

Noncompliant Code Example (Improper &&)

...