{"record":{"id":"e522782da8f69ef7","repo":"apache/hadoop","slug":"source-must-not-be-null","errorCode":null,"errorMessage":"Source must not be null","messagePattern":"Source must not be null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java","lineNumber":1327,"sourceCode":"   * <strong>Note:</strong> Setting <code>preserveFileDate</code> to\n   * {@code true} tries to preserve the file's last modified\n   * date/times using {@link File#setLastModified(long)}, however it is\n   * not guaranteed that the operation will succeed.\n   * If the modification operation fails, no indication is provided.\n   *\n   * @param srcFile  an existing file to copy, must not be {@code null}\n   * @param destFile  the new file, must not be {@code null}\n   * @param preserveFileDate  true if the file date of the copy\n   *  should be the same as the original\n   *\n   * @throws NullPointerException if source or destination is {@code null}\n   * @throws IOException if source or destination is invalid\n   * @throws IOException if an IO error occurs during copying\n   */\n  public static void nativeCopyFileUnbuffered(File srcFile, File destFile,\n      boolean preserveFileDate) throws IOException {\n    if (srcFile == null) {\n      throw new NullPointerException(\"Source must not be null\");\n    }\n    if (destFile == null) {\n      throw new NullPointerException(\"Destination must not be null\");\n    }\n    if (srcFile.exists() == false) {\n      throw new FileNotFoundException(\"Source '\" + srcFile + \"' does not exist\");\n    }\n    if (srcFile.isDirectory()) {\n      throw new IOException(\"Source '\" + srcFile + \"' exists but is a directory\");\n    }\n    if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {\n      throw new IOException(\"Source '\" + srcFile + \"' and destination '\" +\n          destFile + \"' are the same\");\n    }\n    File parentFile = destFile.getParentFile();\n    if (parentFile != null) {\n      if (!parentFile.mkdirs() && !parentFile.isDirectory()) {\n        throw new IOException(\"Destination '\" + parentFile","sourceCodeStart":1309,"sourceCodeEnd":1345,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java#L1309-L1345","documentation":"First guard clause of Storage.nativeCopyFileUnbuffered: it throws NullPointerException before any I/O happens when srcFile is null. The method copies a large file (typically a fsimage/edits segment) using OS-specific unbuffered IO, and its contract requires a non-null regular-file source.","triggerScenarios":"Calling nativeCopyFileUnbuffered with a null File, usually because the caller resolved the source path from a nullable lookup (missing config property, absent checkpoint file) and forwarded it unchecked.","commonSituations":"Unit tests invoking the helper directly; code that maps a configuration value to a File and skips the missing-property case; refactors where a field initialization was dropped.","solutions":["Pass a non-null srcFile","Fail fast at the call site with an actionable message: Objects.requireNonNull(srcFile, \"srcFile\")","Fix the upstream lookup that produced null (e.g. validate the config key exists before building the File)"],"exampleFix":"// before\nStorage.nativeCopyFileUnbuffered(resolveSrc(cfg), dst, true); // resolveSrc returns null\n// after\nFile src = Objects.requireNonNull(resolveSrc(cfg), \"checkpoint src missing from config\");\nStorage.nativeCopyFileUnbuffered(src, dst, true);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(srcFile, \"srcFile must be resolved before copy\");\nif (!srcFile.isFile()) throw new FileNotFoundException(srcFile.toString());","typeGuard":"static boolean isCopyableSource(File f) {\n  return f != null && f.isFile();\n}","tryCatchPattern":null,"preventionTips":["Annotate nullable returns in path-resolution code and check them immediately","Fail fast with Objects.requireNonNull at API boundaries instead of relying on the library's NPE","Validate config-derived paths once at startup, not per call"],"tags":["hdfs","file-copy","null-check","programming-error"],"backgroundTag":"null-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}