Perchè usando l'Iterator in un ciclo while non dovresti mai modificare la List che viene iterata se non tramite l'iterator stesso...
Al massimo puoi rimuovere l'ultimo elemento restituito da iterator.next() tramite iterator.remove()
(vedi codice qui sotto, però non so cosa faccia il tuo metodo clearDownload(), oltre a rimuovere un elemento dalla lista)
Codice:
if (download.getStatus() == Download.COMPLETE || download.getStatus() == Download.CANCELLED)
{
//clearDownload(downloadList.indexOf(download));
iterator.remove();
}
Inoltre il metodo remove() di iterator ti ritorna l'elemento rimosso dalla lista.
Quindi credo tu possa fare così:
Codice:
if (download.getStatus() == Download.COMPLETE || download.getStatus() == Download.CANCELLED)
{
clearDownload( iterator.remove());
}
Modificando opportunamento il metodo clearDownload() in modo che non si occupi più della rimozione dell'elemento Download dalla lista e che accetti in ingresso un oggetto di tipo Download (sempre ammesso che clearDownload() ti serva ancora, altrimenti puoi semplicemente eliminarlo

)
L'indice dell'elemento in ogni caso lo puoi ottenere, prima di chiamare iterator.next(), con:
Codice:
int nextIndex()
-> Returns the index of the element that would be returned by a subsequent call to next.
Il problema dell'eccezione lanciata è spiegato qui:
Quote:
|
The iterators returned by this class's iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. 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.
|
Ciao