apache/iceberg · error

Cannot set value

Error message

Cannot set value

What it means

CharSequenceMap's Map.Entry implementation is read-only: setValue always throws UnsupportedOperationException. Entries in a CharSequenceMap cannot have their values mutated through the entry; use the map's own mutation methods instead.

Source

Thrown at api/src/main/java/org/apache/iceberg/util/CharSequenceMap.java:222

    public int hashCode() {
      return inner.hashCode();
    }

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

      CharSequenceEntry<?> that = (CharSequenceEntry<?>) other;
      return inner.equals(that.inner);
    }

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

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Build a new map with updated values instead of mutating entries in place
  2. Use the map's put/remove methods (if supported) rather than entry.setValue
  3. Copy entries into a mutable HashMap if you need per-entry mutation

Example fix

// before
for (Map.Entry<CharSequence, String> e : map.entrySet()) {
  e.setValue(e.getValue().trim());
}
// after
Map<CharSequence, String> trimmed = new HashMap<>();
map.forEach((k, v) -> trimmed.put(k, v == null ? null : v.trim()));
Defensive patterns

Strategy: type-guard

Type guard

boolean isMutableEntry(Map.Entry<K,V> e) { return !(e instanceof CharSequenceMap.CharSequenceEntry); }

Try / catch

try {
  entry.setValue(newValue);
} catch (UnsupportedOperationException e) {
  // read-only map: rebuild the map instead
}

Prevention

When it happens

Trigger: Iterating a CharSequenceMap's entrySet() and calling entry.setValue(newValue) on a CharSequenceEntry.

Common situations: Generic code that mutates map values while iterating entries (e.g. in-place normalization of values) working on CharSequenceMap, which is commonly used for case-insensitive property maps in Iceberg.

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