apache/hadoop · error · NullPointerException
Destination must not be null
Error message
Destination must not be null
What it means
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.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java:1330
* not guaranteed that the operation will succeed.
* If the modification operation fails, no indication is provided.
*
* @param srcFile an existing file to copy, must not be {@code null}
* @param destFile the new file, must not be {@code null}
* @param preserveFileDate true if the file date of the copy
* should be the same as the original
*
* @throws NullPointerException if source or destination is {@code null}
* @throws IOException if source or destination is invalid
* @throws IOException if an IO error occurs during copying
*/
public static void nativeCopyFileUnbuffered(File srcFile, File destFile,
boolean preserveFileDate) throws IOException {
if (srcFile == null) {
throw new NullPointerException("Source must not be null");
}
if (destFile == null) {
throw new NullPointerException("Destination must not be null");
}
if (srcFile.exists() == false) {
throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
}
if (srcFile.isDirectory()) {
throw new IOException("Source '" + srcFile + "' exists but is a directory");
}
if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {
throw new IOException("Source '" + srcFile + "' and destination '" +
destFile + "' are the same");
}
File parentFile = destFile.getParentFile();
if (parentFile != null) {
if (!parentFile.mkdirs() && !parentFile.isDirectory()) {
throw new IOException("Destination '" + parentFile
+ "' directory cannot be created");
}
}View on GitHub (pinned to 2add963021)
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
Example fix
// before Storage.nativeCopyFileUnbuffered(src, resolveDst(cfg), true); // resolveDst returns null // after File dst = Objects.requireNonNull(resolveDst(cfg), "output dir not configured"); Storage.nativeCopyFileUnbuffered(src, dst, true);
Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull(destFile, "destFile must be resolved before copy");
File parent = destFile.getParentFile();
if (parent != null && !parent.isDirectory() && !parent.mkdirs()) {
throw new IOException("cannot create " + parent);
} Type guard
static boolean isUsableDestination(File f) {
return f != null && (f.getParentFile() == null || f.getParentFile().isDirectory());
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Destination directory config missing so the path builder returns null; tests passing null explicitly; partial refactors leaving the destination unresolved.
Related errors
- Source must not be null
- The filePath should not be null!
- Block cannot be null
- Provided block and location cannot be null
- Source '{srcFile}' does not exist
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/da39155fdd1057d2.
Report an issue: GitHub.