UnsupportedOperationException in Java — What It Means and How to Fix It
What Java's UnsupportedOperationException means and how to fix it.
Published November 2, 2026
UnsupportedOperationException is thrown when an object does not support the requested operation, most often modifying an immutable collection.
What it means and why it happens
Typical cases: List.of(), Collections.unmodifiableList(), Arrays.asList() (fixed size) and read-only views.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
java.lang.UnsupportedOperationException
Practical examples
Code that triggers it
List<String> list = List.of("a", "b");
list.add("c");The fix
List<String> list = new ArrayList<>(List.of("a", "b"));
list.add("c");Copy before mutating
List<String> copy = new ArrayList<>(readOnly);
copy.add("x");Common mistakes
- Modifying List.of or Arrays.asList results.
- Returning internal collections directly.
- Assuming every List is mutable.
Key takeaways
- UnsupportedOperationException: UnsupportedOperationException is thrown when an object does not support the requested operation, most often modifying an immutable collection.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Arrays.asList add?
It has a fixed size; set works, add and remove throw.
How do I find which line caused UnsupportedOperationException?
The error message and stack trace show the file and line; start there and work backwards.