Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/util/ConcurrentModificationException.java
38829 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.util;2627/**28* This exception may be thrown by methods that have detected concurrent29* modification of an object when such modification is not permissible.30* <p>31* For example, it is not generally permissible for one thread to modify a Collection32* while another thread is iterating over it. In general, the results of the33* iteration are undefined under these circumstances. Some Iterator34* implementations (including those of all the general purpose collection implementations35* provided by the JRE) may choose to throw this exception if this behavior is36* detected. Iterators that do this are known as <i>fail-fast</i> iterators,37* as they fail quickly and cleanly, rather that risking arbitrary,38* non-deterministic behavior at an undetermined time in the future.39* <p>40* Note that this exception does not always indicate that an object has41* been concurrently modified by a <i>different</i> thread. If a single42* thread issues a sequence of method invocations that violates the43* contract of an object, the object may throw this exception. For44* example, if a thread modifies a collection directly while it is45* iterating over the collection with a fail-fast iterator, the iterator46* will throw this exception.47*48* <p>Note that fail-fast behavior cannot be guaranteed as it is, generally49* speaking, impossible to make any hard guarantees in the presence of50* unsynchronized concurrent modification. Fail-fast operations51* throw {@code ConcurrentModificationException} on a best-effort basis.52* Therefore, it would be wrong to write a program that depended on this53* exception for its correctness: <i>{@code ConcurrentModificationException}54* should be used only to detect bugs.</i>55*56* @author Josh Bloch57* @see Collection58* @see Iterator59* @see Spliterator60* @see ListIterator61* @see Vector62* @see LinkedList63* @see HashSet64* @see Hashtable65* @see TreeMap66* @see AbstractList67* @since 1.268*/69public class ConcurrentModificationException extends RuntimeException {70private static final long serialVersionUID = -3666751008965953603L;7172/**73* Constructs a ConcurrentModificationException with no74* detail message.75*/76public ConcurrentModificationException() {77}7879/**80* Constructs a {@code ConcurrentModificationException} with the81* specified detail message.82*83* @param message the detail message pertaining to this exception.84*/85public ConcurrentModificationException(String message) {86super(message);87}8889/**90* Constructs a new exception with the specified cause and a detail91* message of {@code (cause==null ? null : cause.toString())} (which92* typically contains the class and detail message of {@code cause}.93*94* @param cause the cause (which is saved for later retrieval by the95* {@link Throwable#getCause()} method). (A {@code null} value is96* permitted, and indicates that the cause is nonexistent or97* unknown.)98* @since 1.799*/100public ConcurrentModificationException(Throwable cause) {101super(cause);102}103104/**105* Constructs a new exception with the specified detail message and106* cause.107*108* <p>Note that the detail message associated with <code>cause</code> is109* <i>not</i> automatically incorporated in this exception's detail110* message.111*112* @param message the detail message (which is saved for later retrieval113* by the {@link Throwable#getMessage()} method).114* @param cause the cause (which is saved for later retrieval by the115* {@link Throwable#getCause()} method). (A {@code null} value116* is permitted, and indicates that the cause is nonexistent or117* unknown.)118* @since 1.7119*/120public ConcurrentModificationException(String message, Throwable cause) {121super(message, cause);122}123}124125126