ServiceLoader double iterator issues
<p>Is this a known issue? I had trouble finding any search results.</p>

<p>When iterating over a ServiceLoader while an iteration already is in progress, the first iteration will be aborted. For example, assuming there are at least two implementations of <code>Foo</code>, the following code will fail with an AssertionError:</p>

<pre><code>ServiceLoader&lt;Foo&gt; loader = ServiceLoader.load(Foo.class);
Iterator&lt;Foo&gt; iter1 = loader.iterator();
iter1.next();

Iterator&lt;Foo&gt; iter2 = loader.iterator();
while (iter2.hasNext()) {
    iter2.next();
}

assert iter1.hasNext();
</code></pre>

<p>This only seems to occur, if the second iterator really terminates. The code will succeed in this variation for example:</p>

<pre><code>ServiceLoader&lt;Foo&gt; loader = ServiceLoader.load(Foo.class);
Iterator&lt;Foo&gt; iter1 = loader.iterator();
iter1.next();

Iterator&lt;Foo&gt; iter2 = loader.iterator();
iter2.next();

assert iter1.hasNext();
</code></pre>

<p>Is this a bug or a feature? :p</p>

<p>Is there a ticket for this already anywhere?</p>
