{"record":{"id":"efaf18f1e52330e8","repo":"apache/iceberg","slug":"getclass-getname-does-not-support-cardinali","errorCode":null,"errorMessage":"${getClass().getName()} does not support cardinality","messagePattern":"(.+?) does not support cardinality","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/deletes/PositionDeleteIndex.java","lineNumber":93,"sourceCode":"   */\n  default void forEach(LongConsumer consumer) {\n    if (isNotEmpty()) {\n      throw new UnsupportedOperationException(getClass().getName() + \" does not support forEach\");\n    }\n  }\n\n  /**\n   * Returns delete files that this index was created from or an empty collection if unknown.\n   *\n   * @return delete files that this index was created from\n   */\n  default Collection<DeleteFile> deleteFiles() {\n    return ImmutableList.of();\n  }\n\n  /** Returns the cardinality of this index. */\n  default long cardinality() {\n    throw new UnsupportedOperationException(getClass().getName() + \" does not support cardinality\");\n  }\n\n  /**\n   * Serializes this index.\n   *\n   * @return a buffer containing the serialized index\n   */\n  default ByteBuffer serialize() {\n    throw new UnsupportedOperationException(getClass().getName() + \" does not support serialize\");\n  }\n\n  /**\n   * Deserializes a position delete index.\n   *\n   * @param bytes an array containing the serialized index\n   * @param deleteFile the delete file that the index is created for\n   * @return the deserialized index\n   */","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/deletes/PositionDeleteIndex.java#L75-L111","documentation":"PositionDeleteIndex.cardinality() returns the number of positions in the index, but the interface default throws UnsupportedOperationException because not every implementation can compute cardinality cheaply (or at all). Callers such as toBlob (serialization) and deletion-vector construction require it.","triggerScenarios":"Calling cardinality() on an implementation that has not overridden the default — e.g. when serializing an index to a blob, building a deletion vector (dv), or in assertEqual and tests that check index size.","commonSituations":"Using a custom or partial PositionDeleteIndex implementation in a code path that builds DeletionVectors, which always need cardinality; e.g. plugging a custom index into DV-based table maintenance.","solutions":["Override cardinality() in the implementation to return the true count of positions","Use BitmapPositionDeleteIndex (or another full implementation) wherever deletion vectors will be produced","At call sites, only request cardinality from indexes created from delete files whose format supports counting positions"],"exampleFix":"// before\n@Override public long cardinality() { throw new UnsupportedOperationException(...); }\n// after\n@Override public long cardinality() { return bitmap.getLongCardinality(); }","handlingStrategy":"type-guard","validationCode":"if (index instanceof BitmapPositionDeleteIndex) { long n = index.cardinality(); } else { /* fall back to delete-file metadata */ }","typeGuard":"boolean supportsCardinality(PositionDeleteIndex idx) { return !(idx.getClass().getSimpleName().startsWith(\"Default\") && isStub(idx)); }","tryCatchPattern":"try { return index.cardinality(); } catch (UnsupportedOperationException e) { return deleteFiles.stream().mapToLong(DeleteFile::contentSizeInBytes).count(); }","preventionTips":["Only request cardinality from indexes backing deletion-vector production","Derive counts from DeleteFile metadata where possible instead of in-memory indexes","Test custom index implementations against the full PositionDeleteIndex contract"],"tags":["java","deletes","deletion-vectors"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}