{"record":{"id":"e836681ee7ec4fc8","repo":"apache/hadoop","slug":"the-filepath-should-not-be-null","errorCode":null,"errorMessage":"The filePath should not be null!","messagePattern":"The filePath should not be null!","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetUtil.java","lineNumber":228,"sourceCode":"    ReplicaInfo wrapper = new FinalizedReplica(0, 0, 0, null, null) {\n      @Override\n      public URI getMetadataURI() {\n        return srcMeta.toURI();\n      }\n\n      @Override\n      public InputStream getDataInputStream(long seekOffset)\n          throws IOException {\n        return Files.newInputStream(blockFile.toPath());\n      }\n    };\n\n    FsDatasetImpl.computeChecksum(wrapper, dstMeta, smallBufferSize, conf);\n  }\n\n  public static void deleteMappedFile(String filePath) throws IOException {\n    if (filePath == null) {\n      throw new IOException(\"The filePath should not be null!\");\n    }\n    boolean result = Files.deleteIfExists(Paths.get(filePath));\n    if (!result) {\n      throw new IOException(\n          \"Failed to delete the mapped file: \" + filePath);\n    }\n  }\n}\n","sourceCodeStart":210,"sourceCodeEnd":237,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetUtil.java#L210-L237","documentation":"FsDatasetUtil.deleteMappedFile cleans up a memory-mapped temporary file used while computing block checksums. The IOException is a plain null guard: the caller passed a null path, meaning internal state about the mapped file was lost before cleanup. It signals a programming error inside the DataNode or test code, not a configuration problem.","triggerScenarios":"Internal caller invokes deleteMappedFile after checksum computation failed before the path was assigned; test code passes null; a race clears the mapped-file holder early.","commonSituations":"Only in custom builds, patched DataNodes, or unit tests exercising checksum computation.","solutions":["Look at the caller of deleteMappedFile in the stack trace and fix it to pass the captured path - assign the path before work begins and delete in a finally block.","No block data is at risk: the mapped file holds only intermediate checksum data; clean leftover temp files if any.","If it is stock unmodified Hadoop code, report it with the stack trace."],"exampleFix":"// before\ndeleteMappedFile(null); // path lost when computation failed early\n\n// after\nString mappedPath = null;\ntry {\n  mappedPath = createMappedFile();\n  compute(mappedPath);\n} finally {\n  if (mappedPath != null) {\n    FsDatasetUtil.deleteMappedFile(mappedPath);\n  }\n}","handlingStrategy":"validation","validationCode":"if (filePath == null) {\n  // nothing to clean: skip the call\n  return;\n}\nFsDatasetUtil.deleteMappedFile(filePath);","typeGuard":null,"tryCatchPattern":"try {\n  FsDatasetUtil.deleteMappedFile(path);\n} catch (IOException e) {\n  // internal caller bug: log with the stack and continue cleanup\n}","preventionTips":["Assign the mapped-file path before any work that can fail; delete in finally.","Never call deleteMappedFile with an untracked path variable.","Write tests that exercise checksum-computation failure paths to catch null-path cleanup bugs."],"tags":["hdfs","datanode","null-check","checksum","programming-error"],"backgroundTag":"null-argument-guard","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}