apache/iceberg · error · UnsupportedOperationException

retainAll is not supported

Error message

retainAll is not supported

What it means

PartitionSet implements only the set operations it needs; retainAll is deliberately unsupported and throws UnsupportedOperationException. Partition sets are append/remove-only structures used during expire/delete planning.

Solutions

  1. Rebuild a new PartitionSet containing only the retained partitions instead of retainAll
  2. Use removeAll for removals, which is supported
  3. Implement your own intersection using contains() filtering

Example fix

// before
set.retainAll(other); // throws
// after
PartitionSet kept = PartitionSet.create(spec);
for (Pair<Integer, StructLike> p : partitions) if (other.contains(p)) kept.add(p);
Defensive patterns

Strategy: type-guard

Type guard

boolean supportsRetainAll(Set<?> s) { return !(s instanceof PartitionSet); }

Try / catch

try { set.retainAll(other); } catch (UnsupportedOperationException e) { /* rebuild set manually */ }

Prevention

When it happens

Trigger: Calling retainAll(Collection) on a PartitionSet, e.g. via generic Set API usage or Collection.retainAll on a set viewed as a PartitionSet.

Common situations: Generic set-algebra code written against java.util.Collection; refactoring that assumed full Set semantics.

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/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/793da205ff1be27d. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/apache/iceberg/util/PartitionSet.java:178

      return Iterables.all(objects, this::contains);
    }
    return false;
  }

  @Override
  public boolean addAll(Collection<? extends Pair<Integer, StructLike>> pairs) {
    boolean changed = false;
    if (pairs != null) {
      for (Pair<Integer, StructLike> pair : pairs) {
        changed |= add(pair);
      }
    }
    return changed;
  }

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

  @Override
  public boolean removeAll(Collection<?> objects) {
    boolean changed = false;
    if (objects != null) {
      for (Object object : objects) {
        changed |= remove(object);
      }
    }
    return changed;
  }

  @Override
  public String toString() {
    StringJoiner result = new StringJoiner(", ", "[", "]");
    for (Map.Entry<Integer, Set<StructLike>> e : partitionSetById.entrySet()) {
      StringJoiner partitionDataJoiner = new StringJoiner(", ");

View on GitHub (pinned to 86d9c8fc54)