# ConcurrentModificationException

public class **ConcurrentModificationException** extends [RuntimeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/RuntimeException.html)  

|---|---|---|
| Known Direct Subclasses [DirectoryIteratorException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/DirectoryIteratorException.html) |---|---| | [DirectoryIteratorException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/file/DirectoryIteratorException.html) | Runtime exception thrown if an I/O error is encountered when iterating over the entries in a directory. | |||

This exception may be thrown by methods that have detected concurrent
modification of an object when such modification is not permissible.


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


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

Note that fail-fast behavior cannot be guaranteed as it is, generally
speaking, impossible to make any hard guarantees in the presence of
unsynchronized concurrent modification. Fail-fast operations
throw `ConcurrentModificationException` on a best-effort basis.
Therefore, it would be wrong to write a program that depended on this
exception for its correctness: *`ConcurrentModificationException` should be used only to detect bugs.*

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Collection.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Iterator.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Spliterator.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/ListIterator.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Vector.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/LinkedList.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/HashSet.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Hashtable.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/TreeMap.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/AbstractList.html`

### Public Constructor Summary

|---|---|
|   | [ConcurrentModificationException](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/ConcurrentModificationException.html#ConcurrentModificationException())() Constructs a ConcurrentModificationException with no detail message. |
|   | [ConcurrentModificationException](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/ConcurrentModificationException.html#ConcurrentModificationException(java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) message) Constructs a `ConcurrentModificationException` with the specified detail message. |
|   | [ConcurrentModificationException](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/ConcurrentModificationException.html#ConcurrentModificationException(java.lang.Throwable))([Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) cause) Constructs a new exception with the specified cause and a detail message of `(cause==null ? null : cause.toString())` (which typically contains the class and detail message of `cause`. |
|   | [ConcurrentModificationException](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/ConcurrentModificationException.html#ConcurrentModificationException(java.lang.String,%20java.lang.Throwable))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) message, [Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) cause) Constructs a new exception with the specified detail message and cause. |

### Inherited Method Summary

From class [java.lang.Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html)

|---|---|
| synchronized final void | [addSuppressed](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#addSuppressed(java.lang.Throwable))([Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) exception) Appends the specified exception to the exceptions that were suppressed in order to deliver this exception. |
| synchronized [Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) | [fillInStackTrace](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#fillInStackTrace())() Fills in the execution stack trace. |
| synchronized [Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) | [getCause](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getCause())() Returns the cause of this throwable or `null` if the cause is nonexistent or unknown. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getLocalizedMessage](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getLocalizedMessage())() Creates a localized description of this throwable. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getMessage](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getMessage())() Returns the detail message string of this throwable. |
| StackTraceElement\[\] | [getStackTrace](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getStackTrace())() Provides programmatic access to the stack trace information printed by `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#printStackTrace()`. |
| synchronized final [Throwable\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) | [getSuppressed](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getSuppressed())() Returns an array containing all of the exceptions that were suppressed, typically by the `try`-with-resources statement, in order to deliver this exception. |
| synchronized [Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) | [initCause](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#initCause(java.lang.Throwable))([Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) cause) Initializes the *cause* of this throwable to the specified value. |
| void | [printStackTrace](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#printStackTrace())() Prints this throwable and its backtrace to the standard error stream. |
| void | [printStackTrace](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#printStackTrace(java.io.PrintWriter))([PrintWriter](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PrintWriter.html) s) Prints this throwable and its backtrace to the specified print writer. |
| void | [printStackTrace](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#printStackTrace(java.io.PrintStream))([PrintStream](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/PrintStream.html) s) Prints this throwable and its backtrace to the specified print stream. |
| void | [setStackTrace](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#setStackTrace(java.lang.StackTraceElement[]))(StackTraceElement\[\] stackTrace) Sets the stack trace elements that will be returned by `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getStackTrace()` and printed by `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#printStackTrace()` and related methods. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#toString())() Returns a short description of this throwable. |

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Constructors

#### public
**ConcurrentModificationException**
()

Constructs a ConcurrentModificationException with no
detail message.

#### public
**ConcurrentModificationException**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) message)

Constructs a `ConcurrentModificationException` with the
specified detail message.

##### Parameters

| message | the detail message pertaining to this exception. |
|---|---|

#### public
**ConcurrentModificationException**
([Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) cause)

Constructs a new exception with the specified cause and a detail
message of `(cause==null ? null : cause.toString())` (which
typically contains the class and detail message of `cause`.

##### Parameters

| cause | the cause (which is saved for later retrieval by the `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getCause()` method). (A `null` value is permitted, and indicates that the cause is nonexistent or unknown.) |
|---|---|

#### public
**ConcurrentModificationException**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) message, [Throwable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html) cause)

Constructs a new exception with the specified detail message and
cause.

Note that the detail message associated with `cause` is
*not* automatically incorporated in this exception's detail
message.

##### Parameters

| message | the detail message (which is saved for later retrieval by the `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getMessage()` method). |
| cause | the cause (which is saved for later retrieval by the `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Throwable.html#getCause()` method). (A `null` value is permitted, and indicates that the cause is nonexistent or unknown.) |
|---|---|