apache/iceberg · error · UnsupportedOperationException

Cannot set value

Error message

Cannot set value

What it means

PartitionEntry is an immutable map entry: setValue is explicitly unsupported because partition entries must not be mutated once constructed. Any call throws UnsupportedOperationException with this message.

Solutions

  1. Don't mutate entries; remove and re-insert a new value via the map API instead
  2. Rebuild the map with new values if mutation is needed
  3. Use the PartitionMap's put to replace values

Example fix

// before
for (Entry<Pair<Integer, StructLike>, V> e : map.entrySet()) e.setValue(v);
// after
map.put(e.getKey(), v); // or rebuild map with updated values
Defensive patterns

Strategy: type-guard

Type guard

boolean isMutableEntry(Entry<?, ?> e) { return !(e instanceof PartitionEntry); }

Try / catch

try { entry.setValue(v); } catch (UnsupportedOperationException e) { map.put(entry.getKey(), v); }

Prevention

When it happens

Trigger: Calling setValue(v) on an Entry obtained from a PartitionMap's entrySet, e.g. generic map-mutation code.

Common situations: Generic code that rewrites map values in-place while iterating entrySet; adaptation of HashMap-style logic to PartitionMap.

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/b93f2270242fa44f. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/apache/iceberg/util/PartitionMap.java:254

    public int hashCode() {
      return Objects.hash(specId, structAndValue);
    }

    @Override
    public boolean equals(Object other) {
      if (this == other) {
        return true;
      } else if (other == null || getClass() != other.getClass()) {
        return false;
      }

      PartitionEntry<?> that = (PartitionEntry<?>) other;
      return specId == that.specId && Objects.equals(structAndValue, that.structAndValue);
    }

    @Override
    public V setValue(V newValue) {
      throw new UnsupportedOperationException("Cannot set value");
    }
  }
}

View on GitHub (pinned to 86d9c8fc54)