{"record":{"id":"da39155fdd1057d2","repo":"apache/hadoop","slug":"destination-must-not-be-null","errorCode":null,"errorMessage":"Destination must not be null","messagePattern":"Destination 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":1330,"sourceCode":"   * 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\n            + \"' directory cannot be created\");\n      }\n    }","sourceCodeStart":1312,"sourceCodeEnd":1348,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java#L1312-L1348","documentation":"Second guard clause of Storage.nativeCopyFileUnbuffered: NullPointerException when destFile is null while srcFile passed its check. Same contract as the source guard - both arguments must be non-null before the unbuffered copy starts.","triggerScenarios":"Calling nativeCopyFileUnbuffered with a null destination File, typically from a caller that built the destination from a null-returning path lookup or an unset output directory setting.","commonSituations":"Destination directory config missing so the path builder returns null; tests passing null explicitly; partial refactors leaving the destination unresolved.","solutions":["Pass a non-null destFile","Fail fast at the call site: Objects.requireNonNull(destFile, \"destFile\")","Validate the output-directory configuration before constructing the destination path"],"exampleFix":"// before\nStorage.nativeCopyFileUnbuffered(src, resolveDst(cfg), true); // resolveDst returns null\n// after\nFile dst = Objects.requireNonNull(resolveDst(cfg), \"output dir not configured\");\nStorage.nativeCopyFileUnbuffered(src, dst, true);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(destFile, \"destFile must be resolved before copy\");\nFile parent = destFile.getParentFile();\nif (parent != null && !parent.isDirectory() && !parent.mkdirs()) {\n  throw new IOException(\"cannot create \" + parent);\n}","typeGuard":"static boolean isUsableDestination(File f) {\n  return f != null && (f.getParentFile() == null || f.getParentFile().isDirectory());\n}","tryCatchPattern":null,"preventionTips":["Resolve and validate destination directories at startup","Use Objects.requireNonNull at the boundary for a clear failure site","In tests, build destinations from @TemporaryFolder rather than hand-built null paths"],"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"}