title: Should listeners be able to remove listeners?
body: <p>Many classes use code similar to the following to fire listeners.</p>
  
  <pre><code>private List&lt;Listener&gt; listeners = new ArrayList&lt;Listener&gt;();
  
  public void fireListener() {
    for(Listener l : listeners) l.someMethod();
  }
  </code></pre>
  
  <p>This works fine until the listener tries to add/remove a listener. This modification from inside the list causes a <code>ConcurrentModificationException</code>. Should we handle this case or should modifying listeners be invalid? What would be the best way to handle add/remove of listeners?</p>
  
  <p><strong>Update:</strong><br>
  Here is one possible solution.</p>
  
  <pre><code>public void fireListener() {
    for(Listener l : listeners.toArray(new Listener[listeners.size()])) {
      if(!listeners.contains(l)) continue;
      l.someMethod();
    }
  }
  </code></pre>