DynamicList extends DynamicCollection<E> implements List<E>, RandomAccess { @Override public void add(int index, E element) { if (element == null) { throw new NullPointerException(); } synchronized (lock) { unsafeAdd(index, element); } }  @Override boolean addAll(int index, Collection<? extends E> c); @Override E set(int index, E element); @Override void add(int index, E element); @Override int indexOf(Object o); @Override int lastIndexOf(Object o); E get(int index); @Override ListIterator<E> listIterator(); @Override ListIterator<E> listIterator(int index); @Override List<E> subList(int fromIndex, int toIndex);  }
@Test public void testRemoveBeforeWhileListIterating() throws Exception { list.add(OBJ_0); list.add(OBJ_1); Iterator iterator = list.iterator(); assertThat(iterator.hasNext(), equalTo(true)); assertThat(iterator.next(), sameInstance(OBJ_0)); list.remove(OBJ_0); assertThat(iterator.hasNext(), equalTo(true)); assertThat(iterator.next(), sameInstance(OBJ_1)); assertThat(iterator.hasNext(), equalTo(false)); }