Search This Blog

Java Exceptions Catalog Part 3: Collections, Concurrency & Data Exceptions

Java Exceptions Catalog - Part 3: Collections, Concurrency & Data Exceptions

Java Exceptions Catalog - Part 3: Collections & Concurrency

Comprehensive guide to data structure faults (java.util), multi-threaded executor and synchronization exceptions (java.util.concurrent), and mathematical rounding issues (java.math).

1. Collections & Utility Exceptions (java.util Package)

JAVA.UTIL

java.util.ConcurrentModificationException

Modifying a collection structural state (adding or removing elements) while iterating over it via a standard loop.

Resolution
Use Iterator.remove(), Collection.removeIf(), or thread-safe collection structures like CopyOnWriteArrayList or ConcurrentHashMap.
JAVA.UTIL

java.util.NoSuchElementException

Requesting the next element from an Iterator, Enumeration, or Optional.get() when no further elements exist.

Resolution
Always verify presence using iterator.hasNext() or optional.isPresent() / optional.orElseThrow().
JAVA.UTIL

java.util.MissingResourceException

ResourceBundle cannot locate a requested property key or resource bundle file.

Resolution
Verify resource file names, package locations on the classpath, and property key spelling in .properties files.
JAVA.UTIL

java.util.InputMismatchException

Thrown by Scanner when a retrieved token does not match the pattern for the expected data type.

JAVA.UTIL

java.util.EmptyStackException

Invoking pop() or peek() on an empty java.util.Stack instance.

JAVA.UTIL

java.util.UnknownFormatConversionException

An unknown conversion specifier flag is passed to String.format() or System.out.printf().

JAVA.UTIL

java.util.FormatFlagsConversionMismatchException

An incompatible format flag and conversion specifier combination is passed to a formatter.

JAVA.UTIL

java.util.IllegalFormatPrecisionException

A negative precision value (other than -1) is supplied to a string format conversion.

JAVA.UTIL

java.util.IllegalFormatWidthException

A negative width value is supplied to a string format specifier.

JAVA.UTIL

java.util.MissingFormatArgumentException

The format string specifies a parameter index or conversion flag that lacks a matching argument.

JAVA.UTIL

java.util.DuplicateFormatFlagsException

Duplicate flags are provided inside a single format specifier argument.

JAVA.UTIL

java.util.IllegalFormatCodePointException

An invalid Unicode code point is passed to a character formatting conversion.

2. Multithreading & Concurrency (java.util.concurrent Package)

CONCURRENCY

java.util.concurrent.RejectedExecutionException

An ExecutorService rejects a task submission because its bounded work queue is saturated or the pool has been shut down.

Resolution
Adjust queue size, implement custom RejectedExecutionHandler (e.g., ThreadPoolExecutor.CallerRunsPolicy), or monitor thread pool capacity.
CONCURRENCY

java.util.concurrent.ExecutionException

Wrapper exception thrown when calling Future.get() on a task that aborted due to an internal uncaught exception.

Resolution
Inspect the root cause by invoking exception.getCause() to debug the underlying task execution error.
CONCURRENCY

java.util.concurrent.CancellationException

Attempting to retrieve the result of a value-producing task (via Future.get()) that was explicitly cancelled.

Resolution
Check task completion status using future.isCancelled() prior to invoking get().
CONCURRENCY

java.util.concurrent.TimeoutException

A blocking operation (e.g., Future.get(timeout, unit) or lock acquisition) timed out before completing.

Resolution
Increase timeout threshold duration, optimize asynchronous task execution time, or handle fallback behavior.
CONCURRENCY

java.util.concurrent.BrokenBarrierException

Thrown when a thread attempts to wait upon a CyclicBarrier that has entered a broken state due to interruption or timeout.

CONCURRENCY

java.util.concurrent.CompletionException

Unchecked wrapper exception thrown when a CompletableFuture task or stage completes exceptionally.

CONCURRENCY

java.util.concurrent.locks.AbstractQueuedSynchronizer

Internal synchronizer exceptions arising from lock acquisition timeouts or corrupted state condition queues.

3. Math & Precision Exceptions (java.math Package)

JAVA.MATH

java.lang.ArithmeticException (BigDecimal division)

Occurs when a BigDecimal division operation yields an inexact non-terminating decimal expansion without a specified rounding mode (e.g., 1 / 3).

Resolution
Explicitly pass a scale and RoundingMode (e.g., bigDecimal.divide(divisor, 2, RoundingMode.HALF_UP)).

No comments:

Post a Comment