Tag

UnsupportedOperationException

0 views collected around this technical thread.

Architect's Guide
Architect's Guide
Mar 26, 2025 · Fundamentals

Avoiding the Fixed‑Size List Pitfall of Arrays.asList in Java

This article explains why using Arrays.asList to convert an array into a List can produce an immutable, fixed‑size list that throws UnsupportedOperationException on add or remove operations, illustrates the issue with real‑world incident details, analyzes the internal implementation, and provides a safe replacement using java.util.ArrayList.

ArrayListArrays.asListCollections
0 likes · 9 min read
Avoiding the Fixed‑Size List Pitfall of Arrays.asList in Java
macrozheng
macrozheng
Feb 10, 2025 · Backend Development

Why Arrays.asList() Can Crash Your Java App and How to Fix It

This article explains how using Arrays.asList() to convert an array into a List creates a fixed‑size collection that throws UnsupportedOperationException on add or remove operations, illustrates the issue with a real e‑commerce incident, and shows how to safely wrap the result with a mutable java.util.ArrayList.

ArrayListArrays.asListCollections
0 likes · 9 min read
Why Arrays.asList() Can Crash Your Java App and How to Fix It
Architect's Guide
Architect's Guide
Jun 2, 2024 · Fundamentals

Pitfalls and Best Practices of Arrays.asList and ArrayList.subList in Java

This article explains how Java's Arrays.asList creates a fixed‑size list that throws UnsupportedOperationException on add/remove, and how ArrayList.subList returns a mutable view whose non‑structural changes affect both the original list and the sublist while structural changes can trigger ConcurrentModificationException, providing code examples and practical guidelines.

ArrayList.subListArrays.asListCollections
0 likes · 9 min read
Pitfalls and Best Practices of Arrays.asList and ArrayList.subList in Java
Top Architect
Top Architect
Mar 29, 2021 · Fundamentals

Pitfalls of Using Arrays.asList and ArrayList.subList in Java

This article explains common traps when using Java's Arrays.asList and ArrayList.subList methods, including why add operations throw UnsupportedOperationException, how subList creates a view that shares modifications with the original list, and the circumstances that lead to ConcurrentModificationException.

ArrayList.subListArrays.asListCollections
0 likes · 8 min read
Pitfalls of Using Arrays.asList and ArrayList.subList in Java
Java Captain
Java Captain
Mar 27, 2021 · Fundamentals

Pitfalls of Using Arrays.asList and ArrayList.subList in Java

This article explains common pitfalls when using Java's Arrays.asList and ArrayList.subList methods, illustrating why add operations cause UnsupportedOperationException, how subList creates a view that shares modifications with the original list, and provides best‑practice recommendations to avoid runtime errors.

ArrayList.subListArrays.asListCollections
0 likes · 8 min read
Pitfalls of Using Arrays.asList and ArrayList.subList in Java
Architecture Digest
Architecture Digest
Dec 22, 2019 · Backend Development

Why Arrays.asList() Throws UnsupportedOperationException When Modifying the Resulting List

The article explains that Java's Arrays.asList() returns a fixed‑size list backed by an internal array, so calling add, remove, or clear on the returned list triggers UnsupportedOperationException, and shows how to avoid the issue by wrapping it in a mutable ArrayList.

Arrays.asListBackendCollections
0 likes · 5 min read
Why Arrays.asList() Throws UnsupportedOperationException When Modifying the Resulting List
Java Captain
Java Captain
Jul 29, 2019 · Backend Development

Why Arrays.asList() Returns an Unmodifiable List in Java

The article explains that Java's Arrays.asList() creates a fixed‑size list backed by the original array, uses an internal ArrayList class without add, remove, or clear methods, and therefore any attempt to modify the list throws UnsupportedOperationException, with work‑arounds shown.

Arrays.asListBackendCollection
0 likes · 4 min read
Why Arrays.asList() Returns an Unmodifiable List in Java