{"record":{"id":"57e4de9d38f8d62e","repo":"apache/hadoop","slug":"remove-is-not-supported-for-provided-storage","errorCode":null,"errorMessage":"Remove is not supported for provided storage","messagePattern":"Remove is not supported for provided storage","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/BlockAliasMap.java","lineNumber":45,"sourceCode":"import org.apache.hadoop.hdfs.protocol.Block;\nimport org.apache.hadoop.hdfs.server.common.BlockAlias;\n\n/**\n * An abstract class used to read and write block maps for provided blocks.\n */\n@InterfaceAudience.Public\n@InterfaceStability.Unstable\npublic abstract class BlockAliasMap<T extends BlockAlias> {\n\n  /**\n   * ImmutableIterator is an Iterator that does not support the remove\n   * operation. This could inherit {@link java.util.Enumeration} but Iterator\n   * is supported by more APIs and Enumeration's javadoc even suggests using\n   * Iterator instead.\n   */\n  public abstract class ImmutableIterator implements Iterator<T> {\n    public void remove() {\n      throw new UnsupportedOperationException(\n          \"Remove is not supported for provided storage\");\n    }\n  }\n\n  /**\n   * An abstract class that is used to read {@link BlockAlias}es\n   * for provided blocks.\n   */\n  public static abstract class Reader<U extends BlockAlias>\n      implements Iterable<U>, Closeable {\n\n    /**\n     * reader options.\n     */\n    public interface Options { }\n\n    /**\n     * @param ident block to resolve","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/blockaliasmap/BlockAliasMap.java#L27-L63","documentation":"BlockAliasMap readers for HDFS provided storage expose an ImmutableIterator — a read-only view of provided block locations — whose remove() unconditionally throws UnsupportedOperationException. This is by design: the alias map is a source of truth about externally managed blocks and cannot be mutated through iteration.","triggerScenarios":"Code iterating a BlockAliasMap.Reader (e.g., over FileRegions of provided blocks) calls iterator.remove() directly, or hands the iterator to a helper library/framework that calls remove() during traversal.","commonSituations":"Porting application code that previously iterated a mutable List<BlockAlias>; using collection utilities or reactive/stream frameworks that mutate the underlying source while iterating.","solutions":["Remove the remove() call — filter with a predicate during iteration or collect items to keep into a new list","If mutation is genuinely needed, maintain your own local Map<Long, FileRegion> copy instead of mutating the reader's view","Audit third-party helpers you pass the iterator to for hidden remove() calls"],"exampleFix":"// before\nIterator<FileRegion> it = reader.iterator();\nwhile (it.hasNext()) {\n  if (stale(it.next())) it.remove(); // throws\n}\n\n// after\nList<FileRegion> kept = new ArrayList<>();\nfor (FileRegion r : reader) {\n  if (!stale(r)) kept.add(r);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Skip remove() on read-only alias map iterators\n@SuppressWarnings(\"rawtypes\")\nstatic boolean isImmutableAliasMapIterator(Iterator<?> it) {\n  return it instanceof BlockAliasMap.ImmutableIterator;\n}","tryCatchPattern":null,"preventionTips":["Treat BlockAliasMap.Reader iterators as read-only by contract","If you need filtered/mutable views, copy into your own collection first","Audit library helpers you pass iterators to for hidden remove() calls"],"tags":["provided-storage","blockaliasmap","iterator","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}