title: NullPointerException on iterating through empty container in java
body: <pre><code>public void clearTrash()
  {
      for (Email i1 : trash.getEmails()) trash.removeEmail(trash.getEmails().indexOf(i1));
  }
  </code></pre>
  
  <p>I thought this would simply return if trash.getEmails() is empty since there is nothing to iterate over, but upon debugging with empty folder it throws NullPointerException. Why doesn't that work?</p>