{"record":{"id":"18139d64a61230f2","repo":"apache/hadoop","slug":"provided-block-and-location-cannot-be-null","errorCode":null,"errorMessage":"Provided block and location cannot be null","messagePattern":"Provided block and location 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":188,"sourceCode":"            .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\n  public void write(@Nonnull Block block,\n      @Nonnull ProvidedStorageLocation providedStorageLocation)\n      throws IOException {\n    if (block == null || providedStorageLocation == null) {\n      throw new IOException(\"Provided block and location cannot be null\");\n    }\n    WriteRequestProto request =\n        WriteRequestProto\n            .newBuilder()\n            .setKeyValuePair(KeyValueProto.newBuilder()\n                .setKey(PBHelperClient.convert(block))\n                .setValue(PBHelperClient.convert(providedStorageLocation))\n                .build())\n            .build();\n\n    ipc(() -> rpcProxy.write(null, request));\n  }\n\n  @Override\n  public String getBlockPoolId() throws IOException {\n    BlockPoolResponseProto response = ipc(() -> rpcProxy.getBlockPoolId(null,\n        BlockPoolRequestProto.newBuilder().build()));\n    return response.getBlockPoolId();","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/InMemoryAliasMapProtocolClientSideTranslatorPB.java#L170-L206","documentation":"Same InMemoryAliasMap translator as read(): write() stores a Block -> ProvidedStorageLocation mapping on the alias-map server. Both arguments are @Nonnull because the WriteRequestProto KeyValueProto needs a full key and value; a null on either side cannot be serialized and fails fast with IOException.","triggerScenarios":"Calling write(block, providedStorageLocation) where block is null or providedStorageLocation is null — e.g. a migration/ingestion tool writing mappings before it has resolved the location, or a partially-initialized ProvidedStorageLocation.","commonSituations":"Provided Storage ingestion tools, custom alias-map loaders, unit tests of the alias map protocol; caller-side data-flow bug, not cluster config.","solutions":["Construct both the Block and the ProvidedStorageLocation (uri, offset, length, version) fully before calling write().","Guard at the data source: skip or reject file-region records whose block or location field is missing instead of passing null.","Add validation/unit tests on the ingestion path that produces the mappings."],"exampleFix":"// before\naliasMap.write(block, null); // location not yet resolved\n\n// after\nif (providedStorageLocation == null || block == null) {\n  throw new IllegalArgumentException(\"block and location are both required\");\n}\naliasMap.write(block, providedStorageLocation);","handlingStrategy":"validation","validationCode":"if (block == null || providedStorageLocation == null) {\n  throw new IllegalArgumentException(\n      \"block and ProvidedStorageLocation are both required\");\n}\naliasMap.write(block, providedStorageLocation);","typeGuard":"static boolean isWritableMapping(Block b, ProvidedStorageLocation l) {\n  return b != null && l != null && l.getPath() != null\n      && l.getLength() >= 0 && l.getOffset() >= 0;\n}","tryCatchPattern":"try {\n  aliasMap.write(block, providedStorageLocation);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"cannot be null\")) {\n    throw new IllegalStateException(\"incomplete mapping passed to alias-map write\", e);\n  }\n  throw e;\n}","preventionTips":["Build ProvidedStorageLocation objects in one factory method that rejects partial data.","Validate file-region records at ingestion time rather than at RPC time.","Unit-test the ingestion path with malformed records to prove they are skipped, not written."],"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-22T20:17:22.307Z"}