{"record":{"id":"38e32a20326b892e","repo":"apache/iceberg","slug":"getclass-getname-does-not-implement-length","errorCode":null,"errorMessage":"${getClass().getName()} does not implement length","messagePattern":"(.+?) does not implement length","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/deletes/FileScopedPositionDeleteWriter.java","lineNumber":76,"sourceCode":"  @Override\n  public void write(PositionDelete<T> positionDelete) {\n    writer(positionDelete.path()).write(positionDelete);\n  }\n\n  private FileWriter<PositionDelete<T>, DeleteWriteResult> writer(CharSequence path) {\n    if (currentWriter == null) {\n      openCurrentWriter(path);\n    } else if (CharSequenceUtil.unequalPaths(currentPath, path)) {\n      closeCurrentWriter();\n      openCurrentWriter(path);\n    }\n\n    return currentWriter;\n  }\n\n  @Override\n  public long length() {\n    throw new UnsupportedOperationException(getClass().getName() + \" does not implement length\");\n  }\n\n  @Override\n  public DeleteWriteResult result() {\n    Preconditions.checkState(closed, \"Cannot get result from unclosed writer\");\n    return new DeleteWriteResult(deleteFiles, referencedDataFiles);\n  }\n\n  @Override\n  public void close() throws IOException {\n    if (!closed) {\n      closeCurrentWriter();\n      this.closed = true;\n    }\n  }\n\n  private void openCurrentWriter(CharSequence path) {\n    Preconditions.checkState(!closed, \"Writer has already been closed\");","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/deletes/FileScopedPositionDeleteWriter.java#L58-L94","documentation":"FileScopedPositionDeleteWriter wraps per-file position delete writers and delegates length() to the current writer. When no per-file writer is active (or the underlying writer type cannot report length), it throws UnsupportedOperationException with the class name, signaling that length is not available from this writer abstraction.","triggerScenarios":"Calling length() on a FileScopedPositionDeleteWriter - the class deliberately does not implement it; callers expecting a measurable output stream length (e.g. generic writer metrics code) hit this.","commonSituations":"Framework code that unconditionally polls writer length for progress reporting or file-size checks; misuse of the file-scoped writer where a rollable/measurable writer (e.g. ClusteredDataWriter-style) was expected.","solutions":["Do not call length() on FileScopedPositionDeleteWriter; obtain sizes from the DeleteWriteResult's deleteFiles after result()","Use a different writer implementation that supports length() if byte-length tracking is required","Report metrics from the wrapped current writer's result files instead of the wrapper","Check whether the code path should be using a fan-out/clustered writer rather than a file-scoped one"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (writer instanceof FileScopedPositionDeleteWriter) {\n  throw new IllegalArgumentException(\"length() not supported; read sizes from result delete files\");\n}","typeGuard":"boolean supportsLength(LengthReportingWriter w) {\n  return !(w instanceof FileScopedPositionDeleteWriter);\n}","tryCatchPattern":"try {\n  long len = writer.length();\n} catch (UnsupportedOperationException e) {\n  long len = writer.result().deleteFiles().stream().mapToLong(DeleteFile::fileSizeInBytes).sum();\n}","preventionTips":["Don't call length() on file-scoped writers; use DeleteWriteResult sizes","Pick a writer implementation whose contract matches metric needs","Avoid generic code that assumes all writers report length","Check the class hierarchy before relying on inherited metric APIs"],"tags":["unsupported-operation","writer","position-delete"],"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-14T11:17:12.474Z"}