{"record":{"id":"bf47449e4047abe0","repo":"apache/hadoop","slug":"block-cannot-be-null","errorCode":null,"errorMessage":"Block cannot be null","messagePattern":"Block cannot be null","errorType":"validation","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/InMemoryAliasMapProtocolClientSideTranslatorPB.java","lineNumber":165,"sourceCode":"        .collect(Collectors.toList());\n    BlockProto nextMarker = response.getNextMarker();\n\n    if (nextMarker.isInitialized()) {\n      return new InMemoryAliasMap.IterationResult(fileRegions,\n          Optional.of(PBHelperClient.convert(nextMarker)));\n    } else {\n      return new InMemoryAliasMap.IterationResult(fileRegions,\n          Optional.empty());\n    }\n  }\n\n  @Nonnull\n  @Override\n  public Optional<ProvidedStorageLocation> read(@Nonnull Block block)\n      throws IOException {\n\n    if (block == null) {\n      throw new IOException(\"Block cannot be null\");\n    }\n    ReadRequestProto request =\n        ReadRequestProto\n            .newBuilder()\n            .setKey(PBHelperClient.convert(block))\n            .build();\n    ReadResponseProto response = ipc(() -> rpcProxy.read(null, request));\n\n    ProvidedStorageLocationProto providedStorageLocation =\n        response.getValue();\n    if (providedStorageLocation.isInitialized()) {\n      return Optional.of(PBHelperClient.convert(providedStorageLocation));\n    }\n    return Optional.empty();\n\n  }\n\n  @Override","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/InMemoryAliasMapProtocolClientSideTranslatorPB.java#L147-L183","documentation":"Client-side translator for the InMemoryAliasMap protocol, used by HDFS Provided Storage to map a Block to its ProvidedStorageLocation (path, offset, length, version) on an external store via RPC. read() refuses a null Block because the protobuf ReadRequestProto requires a key. This is a caller-input precondition failure, not a server-side fault.","triggerScenarios":"Calling InMemoryAliasMap.read(block) with null: an alias-map lookup loop passing an uninitialized Block, a test invoking the translator directly, or custom ProvidedStorage code that drops the Block before resolution.","commonSituations":"Developing or integrating Provided Storage (S3, Azure, LocalProv) with a shared InMemoryAliasMap/LevelDBAliasMap server; almost always a caller bug rather than a configuration problem.","solutions":["Fix the caller to construct and pass a non-null Block (built from the block id being resolved).","If absence is legitimate in your flow, check the alias map with contains()/Optional before calling read().","Add a unit test or static null-check (Nullaway/CheckerFramework) asserting the lookup path never passes null."],"exampleFix":"// before\nProvidedStorageLocation loc = aliasMap.read(block).get(); // block may be null\n\n// after\nif (block == null) {\n  throw new IllegalArgumentException(\"block required for alias-map lookup\");\n}\nOptional<ProvidedStorageLocation> loc = aliasMap.read(block);","handlingStrategy":"validation","validationCode":"if (block == null) {\n  throw new IllegalArgumentException(\n      \"block must be non-null before alias-map read()\");\n}\nOptional<ProvidedStorageLocation> loc = aliasMap.read(block);","typeGuard":"static boolean isResolvableBlock(Block b) {\n  return b != null && b.getBlockId() > 0;\n}","tryCatchPattern":"try {\n  Optional<ProvidedStorageLocation> loc = aliasMap.read(block);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Block cannot be null\")) {\n    // caller bug: fix the producer of the null Block; do not retry\n    throw new IllegalStateException(\"alias-map read called with null Block\", e);\n  }\n  throw e;\n}","preventionTips":["Never let alias-map lookup loops pass uninitialized Block values; validate the producer of the blocks.","Annotate producer APIs @Nonnull and run a null analyzer (Nullaway/CheckerFramework) in CI.","Cover the lookup path with unit tests that include empty/absent block records."],"tags":["hdfs","provided-storage","alias-map","null-check","rpc-client"],"backgroundTag":"null-argument-precondition","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}