apache/beam · error · java.lang.UnsupportedOperationException

UnsupportedOperationException

Error message

UnsupportedOperationException

What it means

The List<T> returned by IterableBackedListViewFn (a PCollectionView materialization) is a read-only view; removeAll(Collection) deliberately throws UnsupportedOperationException because side inputs are immutable once materialized.

Solutions

  1. Copy into a mutable list first: new ArrayList<>(viewedList), then call removeAll.
  2. Reformulate as a filter: build the new list by streaming the view and excluding elements you would remove.
  3. Do the removal on the PCollection itself (e.g. Filter/ParDo) before creating the view.

Example fix

// before
sideInputList.removeAll(blacklist);
// after
List<T> filtered = new ArrayList<>(sideInputList);
filtered.removeAll(blacklist);
Defensive patterns

Strategy: fallback

Try / catch

List<T> mutable;
try {
  viewedList.removeAll(toRemove);
  mutable = viewedList;
} catch (UnsupportedOperationException e) {
  mutable = new ArrayList<>(viewedList);
  mutable.removeAll(toRemove);
}

Prevention

When it happens

Trigger: Calling removeAll(...) on the List obtained from a side input view (e.g. sideInput(PCollectionList view) result) inside a DoFn or user code.

Common situations: Treating the side input like a regular ArrayList and trying to bulk-remove elements during pipeline processing; mutating a collection captured from sideInput() inside a ParDo.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/cf03f1468290154d. Report an issue: GitHub.

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/values/PCollectionViews.java:1234

        @Override
        public boolean addAll(Collection<? extends T> c) {
          throw new UnsupportedOperationException();
        }

        @Override
        public boolean addAll(int index, Collection<? extends T> c) {
          throw new UnsupportedOperationException();
        }

        @Override
        public boolean removeAll(Collection<?> c) {
          throw new UnsupportedOperationException();
        }

        @Override
        public boolean retainAll(Collection<?> c) {
          throw new UnsupportedOperationException();
        }

        @Override
        public void clear() {
          throw new UnsupportedOperationException();
        }

        @Override
        public T set(int index, T element) {
          throw new UnsupportedOperationException();
        }

        @Override
        public void add(int index, T element) {
          throw new UnsupportedOperationException();
        }

        @Override

View on GitHub (pinned to 12126d8942)