title: Why no ConcurrentModificationException in this situation with LinkedList iterator?
body: <p>Consider the following code snippet:</p>
  
  <pre><code>List&lt;String&gt; list = new LinkedList&lt;&gt;();
  list.add("Hello");
  list.add("My");
  list.add("Son");
  
  for (String s: list){
      if (s.equals("My")) list.remove(s);
      System.out.printf("s=%s, list=%s\n",s,list.toString());
  }
  </code></pre>
  
  <p>This results in output:</p>
  
  <p>s=Hello, list=[Hello, My, Son]<br>
  s=My, list=[Hello, Son]</p>
  
  <p>So clearly the loop was only entered twice, and the third element, "Son", never gets visited. From the underlying library code, it looks like what happens is that the <code>hasNext()</code> method in the iterator doesn't check for concurrent modification, only the size against the next index. Since the size has been reduced by 1 by the <code>remove()</code> call, the loop simply doesn't get entered again, but no ConcurrentModificationException is thrown. </p>
  
  <p>This seems to contradict the contract of the iterator: </p>
  
  <blockquote>
    <p>The list-iterator is <i>fail-fast</i>: if the list is structurally modified at any time after the Iterator is created, in any way except through the list-iterator's own <code>remove</code> or <code>add</code> methods, the list-iterator will throw a <code>ConcurrentModificationException</code>.  Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.</p>
  </blockquote>
  
  <p>Is this a bug? Again, the contract of the iterator definitely appears to be disobeyed here - the structure of the list is structurally modified by something other than the iterator in the middle of iteration.        </p>