jaroslav@557: /* jaroslav@557: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. jaroslav@557: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@557: * jaroslav@557: * This code is free software; you can redistribute it and/or modify it jaroslav@557: * under the terms of the GNU General Public License version 2 only, as jaroslav@557: * published by the Free Software Foundation. Oracle designates this jaroslav@557: * particular file as subject to the "Classpath" exception as provided jaroslav@557: * by Oracle in the LICENSE file that accompanied this code. jaroslav@557: * jaroslav@557: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@557: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@557: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@557: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@557: * accompanied this code). jaroslav@557: * jaroslav@557: * You should have received a copy of the GNU General Public License version jaroslav@557: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@557: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@557: * jaroslav@557: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@557: * or visit www.oracle.com if you need additional information or have any jaroslav@557: * questions. jaroslav@557: */ jaroslav@557: jaroslav@557: package java.util; jaroslav@557: jaroslav@557: /** jaroslav@557: * This exception may be thrown by methods that have detected concurrent jaroslav@557: * modification of an object when such modification is not permissible. jaroslav@557: *

jaroslav@557: * For example, it is not generally permissible for one thread to modify a Collection jaroslav@557: * while another thread is iterating over it. In general, the results of the jaroslav@557: * iteration are undefined under these circumstances. Some Iterator jaroslav@557: * implementations (including those of all the general purpose collection implementations jaroslav@557: * provided by the JRE) may choose to throw this exception if this behavior is jaroslav@557: * detected. Iterators that do this are known as fail-fast iterators, jaroslav@557: * as they fail quickly and cleanly, rather that risking arbitrary, jaroslav@557: * non-deterministic behavior at an undetermined time in the future. jaroslav@557: *

jaroslav@557: * Note that this exception does not always indicate that an object has jaroslav@557: * been concurrently modified by a different thread. If a single jaroslav@557: * thread issues a sequence of method invocations that violates the jaroslav@557: * contract of an object, the object may throw this exception. For jaroslav@557: * example, if a thread modifies a collection directly while it is jaroslav@557: * iterating over the collection with a fail-fast iterator, the iterator jaroslav@557: * will throw this exception. jaroslav@557: * jaroslav@557: *

Note that fail-fast behavior cannot be guaranteed as it is, generally jaroslav@557: * speaking, impossible to make any hard guarantees in the presence of jaroslav@557: * unsynchronized concurrent modification. Fail-fast operations jaroslav@557: * throw {@code ConcurrentModificationException} on a best-effort basis. jaroslav@557: * Therefore, it would be wrong to write a program that depended on this jaroslav@557: * exception for its correctness: {@code ConcurrentModificationException} jaroslav@557: * should be used only to detect bugs. jaroslav@557: * jaroslav@557: * @author Josh Bloch jaroslav@557: * @see Collection jaroslav@557: * @see Iterator jaroslav@557: * @see ListIterator jaroslav@557: * @see Vector jaroslav@557: * @see LinkedList jaroslav@557: * @see HashSet jaroslav@557: * @see Hashtable jaroslav@557: * @see TreeMap jaroslav@557: * @see AbstractList jaroslav@557: * @since 1.2 jaroslav@557: */ jaroslav@557: public class ConcurrentModificationException extends RuntimeException { jaroslav@557: private static final long serialVersionUID = -3666751008965953603L; jaroslav@557: jaroslav@557: /** jaroslav@557: * Constructs a ConcurrentModificationException with no jaroslav@557: * detail message. jaroslav@557: */ jaroslav@557: public ConcurrentModificationException() { jaroslav@557: } jaroslav@557: jaroslav@557: /** jaroslav@557: * Constructs a {@code ConcurrentModificationException} with the jaroslav@557: * specified detail message. jaroslav@557: * jaroslav@557: * @param message the detail message pertaining to this exception. jaroslav@557: */ jaroslav@557: public ConcurrentModificationException(String message) { jaroslav@557: super(message); jaroslav@557: } jaroslav@557: jaroslav@557: /** jaroslav@557: * Constructs a new exception with the specified cause and a detail jaroslav@557: * message of {@code (cause==null ? null : cause.toString())} (which jaroslav@557: * typically contains the class and detail message of {@code cause}. jaroslav@557: * jaroslav@557: * @param cause the cause (which is saved for later retrieval by the jaroslav@557: * {@link Throwable#getCause()} method). (A {@code null} value is jaroslav@557: * permitted, and indicates that the cause is nonexistent or jaroslav@557: * unknown.) jaroslav@557: * @since 1.7 jaroslav@557: */ jaroslav@557: public ConcurrentModificationException(Throwable cause) { jaroslav@557: super(cause); jaroslav@557: } jaroslav@557: jaroslav@557: /** jaroslav@557: * Constructs a new exception with the specified detail message and jaroslav@557: * cause. jaroslav@557: * jaroslav@557: *

Note that the detail message associated with cause is jaroslav@557: * not automatically incorporated in this exception's detail jaroslav@557: * message. jaroslav@557: * jaroslav@557: * @param message the detail message (which is saved for later retrieval jaroslav@557: * by the {@link Throwable#getMessage()} method). jaroslav@557: * @param cause the cause (which is saved for later retrieval by the jaroslav@557: * {@link Throwable#getCause()} method). (A {@code null} value jaroslav@557: * is permitted, and indicates that the cause is nonexistent or jaroslav@557: * unknown.) jaroslav@557: * @since 1.7 jaroslav@557: */ jaroslav@557: public ConcurrentModificationException(String message, Throwable cause) { jaroslav@557: super(message, cause); jaroslav@557: } jaroslav@557: }