{"record":{"id":"61ad9d89ad37b56c","repo":"apache/iceberg","slug":"cannot-set-value","errorCode":null,"errorMessage":"Cannot set value","messagePattern":"Cannot set value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/util/CharSequenceMap.java","lineNumber":222,"sourceCode":"    public int hashCode() {\n      return inner.hashCode();\n    }\n\n    @Override\n    public boolean equals(Object other) {\n      if (this == other) {\n        return true;\n      } else if (other == null || getClass() != other.getClass()) {\n        return false;\n      }\n\n      CharSequenceEntry<?> that = (CharSequenceEntry<?>) other;\n      return inner.equals(that.inner);\n    }\n\n    @Override\n    public V setValue(V value) {\n      throw new UnsupportedOperationException(\"Cannot set value\");\n    }\n  }\n}\n","sourceCodeStart":204,"sourceCodeEnd":226,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/util/CharSequenceMap.java#L204-L226","documentation":"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.","triggerScenarios":"Iterating a CharSequenceMap's entrySet() and calling entry.setValue(newValue) on a CharSequenceEntry.","commonSituations":"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.","solutions":["Build a new map with updated values instead of mutating entries in place","Use the map's put/remove methods (if supported) rather than entry.setValue","Copy entries into a mutable HashMap if you need per-entry mutation"],"exampleFix":"// before\nfor (Map.Entry<CharSequence, String> e : map.entrySet()) {\n  e.setValue(e.getValue().trim());\n}\n// after\nMap<CharSequence, String> trimmed = new HashMap<>();\nmap.forEach((k, v) -> trimmed.put(k, v == null ? null : v.trim()));","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"boolean isMutableEntry(Map.Entry<K,V> e) { return !(e instanceof CharSequenceMap.CharSequenceEntry); }","tryCatchPattern":"try {\n  entry.setValue(newValue);\n} catch (UnsupportedOperationException e) {\n  // read-only map: rebuild the map instead\n}","preventionTips":["Treat entries from CharSequenceMap.entrySet() as immutable","Copy into a HashMap before bulk value mutation","Never write generic entry-mutating helpers without checking map entry immutability"],"tags":["java","map","immutable","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}