apache/hadoop · error · IOException
Path is null
Error message
Path is null
What it means
NativeIO.getStat(String path) refuses a null argument up front: it logs 'Path is null' and throws IOException. It is a precondition guard so the JNI layer never receives a null pointer, which would produce a crash or an opaque native error. The real bug is upstream — wherever the null path originated.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/nativeio/NativeIO.java:613
}
}
}
return stat;
}
/**
* Return the file stat for a file path.
*
* @param path file path
* @return the file stat
* @throws IOException thrown if there is an IO error while obtaining the
* file stat
*/
public static Stat getStat(String path) throws IOException {
if (path == null) {
String errMessage = "Path is null";
LOG.warn(errMessage);
throw new IOException(errMessage);
}
Stat stat = null;
try {
if (!Shell.WINDOWS) {
stat = stat(path);
stat.owner = getName(IdCache.USER, stat.ownerId);
stat.group = getName(IdCache.GROUP, stat.groupId);
} else {
stat = stat(path);
}
} catch (NativeIOException nioe) {
LOG.warn("NativeIO.getStat error ({}): {} -- file path: {}",
nioe.getErrorCode(), nioe.getMessage(), path);
throw new PathIOException(path, nioe);
}
return stat;
}
View on GitHub (pinned to 2add963021)
Solutions
- Null-check the path at its source and fail with context naming the config key or field that was null.
- Use Objects.requireNonNull(path, "path") to fail fast at the caller with a better message than the IO guard.
- Trace the producer: log the variable right before passing it so the null's origin is visible.
Example fix
// before
Stat st = NativeIO.getStat(maybeNullPath);
// after
Stat st = NativeIO.getStat(
Objects.requireNonNull(path, "path must be set (source: config 'data.dir')")); Defensive patterns
Strategy: validation
Validate before calling
if (path == null) {
throw new IllegalArgumentException("path required (source: " + sourceName + ")");
}
Stat st = NativeIO.getStat(path); Prevention
- Use Objects.requireNonNull with a descriptive label at API edges.
- Never let Map.get()/Optional-style access flow directly into IO calls.
- Check path producers (getParent, config lookups) for documented null returns.
When it happens
Trigger: Calling NativeIO.getStat(null), typically with a null produced earlier: File.getParent() at a root path returning null, a missing config property, Map.get() returning null, or Optional-style access on an absent value.
Common situations: Path derivation like file.getParent() on root-relative files; typo'd configuration keys yielding null; data structures populated conditionally so the key is sometimes absent.
Related errors
- key cannot be null
- key can not be null
- Key may not be null
- Failed to rename %s to %s, file already exists or not empty!
- tokenStr cannot be null
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/00db5d6cc3f99c73.
Report an issue: GitHub.