{"record":{"id":"c798f01e56b8719c","repo":"apache/iceberg","slug":"avro-does-not-support-file-encryption-keys","errorCode":null,"errorMessage":"Avro does not support file encryption keys","messagePattern":"Avro does not support file encryption keys","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/avro/AvroFormatModel.java","lineNumber":151,"sourceCode":"      this.content = newContent;\n      return this;\n    }\n\n    @Override\n    public ModelWriteBuilder<D, S> metricsConfig(MetricsConfig metricsConfig) {\n      internal.metricsConfig(metricsConfig);\n      return this;\n    }\n\n    @Override\n    public ModelWriteBuilder<D, S> overwrite() {\n      internal.overwrite();\n      return this;\n    }\n\n    @Override\n    public ModelWriteBuilder<D, S> withFileEncryptionKey(ByteBuffer encryptionKey) {\n      throw new UnsupportedOperationException(\"Avro does not support file encryption keys\");\n    }\n\n    @Override\n    public ModelWriteBuilder<D, S> withAADPrefix(ByteBuffer aadPrefix) {\n      throw new UnsupportedOperationException(\"Avro does not support AAD prefix\");\n    }\n\n    @Override\n    public FileAppender<D> build() throws IOException {\n      switch (content) {\n        case DATA:\n          internal.createContextFunc(Avro.WriteBuilder.Context::dataContext);\n          internal.createWriterFunc(\n              avroSchema -> writerFunction.write(schema, avroSchema, engineSchema));\n          break;\n        case EQUALITY_DELETES:\n          internal.createContextFunc(Avro.WriteBuilder.Context::deleteContext);\n          internal.createWriterFunc(","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/avro/AvroFormatModel.java#L133-L169","documentation":"The Avro format model's ModelWriteBuilder.withFileEncryptionKey is unsupported: Avro file writing in Iceberg does not implement file-level encryption keys (unlike Parquet). Calling this builder method always throws UnsupportedOperationException. To write encrypted files, use a format that supports encryption, such as Parquet.","triggerScenarios":"Calling writeBuilder(table.io(), table.location()).withFileEncryptionKey(key) with content type set to Avro, e.g. while configuring table properties for encryption and then writing Avro manifests/data files through the generic FormatModel API.","commonSituations":"Configuring encryption generically across formats and hitting the Avro path; code that assumes all formats support write encryption keys; migrating Parquet writes to Avro without removing encryption settings.","solutions":["Use Parquet (or ORC with format-appropriate support) when file encryption keys are required","Remove the withFileEncryptionKey call when writing Avro files","Gate encryption configuration on the actual file format before calling the builder","Store encryption at a different layer (e.g. storage-side encryption) instead of Avro file-level keys"],"exampleFix":"// before\nFormatModel model = table.formatModel(\"avro\");\nmodel.writeBuilder(io, location).withFileEncryptionKey(key).build();\n\n// after\nif (\"parquet\".equals(format)) {\n  model.writeBuilder(io, location).withFileEncryptionKey(key).build();\n} else {\n  model.writeBuilder(io, location).build();\n}","handlingStrategy":"validation","validationCode":"if (\"avro\".equals(format) && encryptionKey != null) { throw new IllegalArgumentException(\"Avro does not support file encryption keys\"); }","typeGuard":"boolean supportsEncryptionKeys(FormatModel m) { return !(m instanceof AvroFormatModel); }","tryCatchPattern":"try { builder.withFileEncryptionKey(key); } catch (UnsupportedOperationException e) { /* fall back to unencrypted or Parquet */ }","preventionTips":["Check format capabilities before applying encryption builder options","Route encrypted writes to Parquet","Keep encryption config per-format, not global"],"tags":["avro","encryption","unsupported"],"backgroundTag":"operation-not-supported","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"}