{"record":{"id":"aa2e3bef72173a6e","repo":"apache/iceberg","slug":"this-getclass-getname-doesn-t-implement-cop","errorCode":null,"errorMessage":"${this.getClass().getName()} doesn't implement copyWithLength","messagePattern":"(.+?) doesn't implement copyWithLength","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/encryption/NativeEncryptionKeyMetadata.java","lineNumber":44,"sourceCode":"  ByteBuffer encryptionKey();\n\n  /** Additional authentication data as a {@link ByteBuffer} */\n  ByteBuffer aadPrefix();\n\n  /** Encrypted file length */\n  default Long fileLength() {\n    throw new UnsupportedOperationException(\n        this.getClass().getName() + \" doesn't implement fileLength\");\n  }\n\n  /**\n   * Copy this key metadata and set the file length.\n   *\n   * @param length length of the encrypted file in bytes\n   * @return a copy of this key metadata (key and AAD) with the file length\n   */\n  default NativeEncryptionKeyMetadata copyWithLength(long length) {\n    throw new UnsupportedOperationException(\n        this.getClass().getName() + \" doesn't implement copyWithLength\");\n  }\n}\n","sourceCodeStart":26,"sourceCodeEnd":48,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/encryption/NativeEncryptionKeyMetadata.java#L26-L48","documentation":"NativeEncryptionKeyMetadata.copyWithLength is a default method that throws UnsupportedOperationException. It must be overridden to return a copy of the key metadata carrying the given encrypted file length; the default signals the implementation does not support length tracking.","triggerScenarios":"Calling copyWithLength(length) on a NativeEncryptionKeyMetadata implementation that did not override it, typically when a writer needs to attach the final encrypted file size to key metadata.","commonSituations":"Custom or older native encryption key metadata implementations predating copyWithLength; third-party integration code that never implemented the length-copy contract.","solutions":["Override copyWithLength(long) in your implementation to return a copy with the length set","Use a key metadata implementation that supports length copying","Update the library providing the key metadata class to a version that implements it"],"exampleFix":"// before\nclass MyKeyMetadata implements NativeEncryptionKeyMetadata { /* no copyWithLength */ }\n// after\nclass MyKeyMetadata implements NativeEncryptionKeyMetadata {\n  @Override public NativeEncryptionKeyMetadata copyWithLength(long length) {\n    return new MyKeyMetadata(kekId(), keyId(), aadPrefix(), length);\n  }\n}","handlingStrategy":"try-catch","validationCode":"try { km.copyWithLength(0L); return true; } catch (UnsupportedOperationException e) { return false; }","typeGuard":null,"tryCatchPattern":"try { withLength = km.copyWithLength(length); }\ncatch (UnsupportedOperationException e) { withLength = null; /* impl lacks length support */ }","preventionTips":["Override copyWithLength in every NativeEncryptionKeyMetadata implementation","Keep custom key metadata classes in sync with interface additions","Add integration tests that call copyWithLength during file writing"],"tags":["encryption","unsupported-operation","native-encryption"],"backgroundTag":"method-not-implemented","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"}