CreateOnWriteList implements List<E> { @Override public E set(int index, E element) { if (wrapped != null) { return wrapped.set(index, element); } throw new UnsupportedOperationException(); }  abstract List<E> newList(); @Override boolean add(E e); @Override void add(int index, E element); @Override boolean addAll(Collection<? extends E> c); @Override boolean addAll(int index, Collection<? extends E> c); @Override void clear(); @Override boolean contains(Object o); @Override boolean containsAll(Collection<?> c); @Override E get(int index); @Override int indexOf(Object o); @Override boolean isEmpty(); @Override @SuppressWarnings("unchecked") Iterator<E> iterator(); @Override int lastIndexOf(Object o); @Override @SuppressWarnings("unchecked") ListIterator<E> listIterator(); @Override @SuppressWarnings("unchecked") ListIterator<E> listIterator(int index); @Override boolean remove(Object o); @Override E remove(int index); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override E set(int index, E element); @Override int size(); @Override @SuppressWarnings("unchecked") List<E> subList(int fromIndex, int toIndex); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override String toString(); @Override boolean equals(Object obj);  }
@Test(expected = UnsupportedOperationException.class) public void testListPresetSet() { assertNull(_list); List<String> l = getListPreset(); assertTrue(_list instanceof CreateOnWriteList); assertTrue(l instanceof CreateOnWriteList); assertNull(getListPreset().set(0, "a")); }
@Test(expected = UnsupportedOperationException.class) public void testListNullSet() { assertNull(_list); List<String> l = getListNull(); assertNull(_list); assertTrue(l instanceof CreateOnWriteList); assertNull(getListNull().set(0, "a")); }