package hudson.util;

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

/**
 * {@link List}-like implementation that has copy-on-write semantics.
 *
 * <p>
 * This class is suitable where the write operation is relatively uncommon.
 *
 * @author Kohsuke Kawaguchi
 */
public class CopyOnWriteList<E> implements Iterable<E> {
    private volatile List<E> core;

    public CopyOnWriteList(List<E> core) {
        this.core = new ArrayList<E>(core);
    }

    public CopyOnWriteList() {
        this.core = Collections.emptyList();
    }

    public synchronized void add(E e) {
        List<E> n = new ArrayList<E>(core);
        n.add(e);
        core = n;
    }

    /**
     * Removes an item from the list.
     *
     * @return
     *      true if the list contained the item. False if it didn't,
     *      in which case there's no change.
     */
    public synchronized boolean remove(E e) {
        List<E> n = new ArrayList<E>(core);
        boolean r = n.remove(e);
        core = n;
        return r;
    }

    public Iterator<E> iterator() {
        return core.iterator();
    }
}

@@ -1081,70 +1081,540 @@
     
-public Iterator%3CE%3E iterator() %7B%0A        return core.iterator()
+/**%0A     * Returns an iterator.%0A     *%0A     * The returned iterator doesn't support the %3Ctt%3Eremove%3C/tt%3E operation.%0A     */%0A    public Iterator%3CE%3E iterator() %7B%0A        final Iterator%3CE%3E itr = core.iterator();%0A        return new Iterator%3CE%3E() %7B%0A            public boolean hasNext() %7B%0A                return itr.hasNext();%0A            %7D%0A%0A            public E next() %7B%0A                return itr.next();%0A            %7D%0A%0A            public void remove() %7B%0A                throw new UnsupportedOperationException();%0A            %7D%0A        %7D
 ;%0A  

fixed a problem in the iterator as pointed out by Jesse.