title: Null check in an enhanced for loop
body: <p>What is the best way to guard against null in a for loop in Java? </p>
  
  <p>This seems ugly :</p>
  
  <pre><code>if (someList != null) {
      for (Object object : someList) {
          // do whatever
      }
  }
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>if (someList == null) {
      return; // Or throw ex
  }
  for (Object object : someList) {
      // do whatever
  }
  </code></pre>
  
  <p>There might not be any other way. Should they have put it in the <code>for</code> construct itself, if it is null then don't run the loop?</p>