apache/hadoop · error · NativeIOException
ENOENT
ENOENT
Error message
No such file or directory
What it means
On Windows, NativeIO.chmod maps the native failure: Win32 error 3 (ERROR_PATH_NOT_FOUND) is re-thrown as NativeIOException("No such file or directory", Errno.ENOENT). It means chmod(2) failed because the target path does not exist at the moment of the call — a plain missing-file error surfaced through the native wrapper.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/nativeio/NativeIO.java:398
*/
public static native FileDescriptor open(String path, int flags, int mode) throws IOException;
/** Wrapper around fstat(2) */
private static native Stat fstat(FileDescriptor fd) throws IOException;
/** Wrapper around stat(2). */
private static native Stat stat(String path) throws IOException;
/** Native chmod implementation. On UNIX, it is a wrapper around chmod(2) */
private static native void chmodImpl(String path, int mode) throws IOException;
public static void chmod(String path, int mode) throws IOException {
if (!Shell.WINDOWS) {
chmodImpl(path, mode);
} else {
try {
chmodImpl(path, mode);
} catch (NativeIOException nioe) {
if (nioe.getErrorCode() == 3) {
throw new NativeIOException("No such file or directory",
Errno.ENOENT);
} else {
LOG.warn(String.format("NativeIO.chmod error (%d): %s",
nioe.getErrorCode(), nioe.getMessage()));
throw new NativeIOException("Unknown error", Errno.UNKNOWN);
}
}
}
}
/** Wrapper around posix_fadvise(2) */
static native void posix_fadvise(
FileDescriptor fd, long offset, long len, int flags) throws NativeIOException;
/** Wrapper around sync_file_range(2) */
static native void sync_file_range(
FileDescriptor fd, long offset, long nbytes, int flags) throws NativeIOException;
View on GitHub (pinned to 2add963021)
Solutions
- Log and inspect the exact path string passed in — Windows path construction (prefixes, separators, empty segments) is the usual culprit.
- Check Files.exists(Paths.get(path)) immediately before the call; if it races with a deleter, treat ENOENT as benign ('already gone').
- If the file should exist, fix the lifecycle: whoever deletes/moves it must not race the permission change.
Defensive patterns
Strategy: try-catch
Validate before calling
Path p = Paths.get(path);
if (!Files.exists(p)) {
// create the file first, or skip the chmod as nothing to do
} Try / catch
try {
NativeIO.chmod(path, mode);
} catch (NativeIOException e) {
if (e.getErrno() == Errno.ENOENT) {
// target already gone: benign if deleters race us, otherwise surface
} else { throw e; }
} Prevention
- Log absolute paths on failure — Windows path construction is the usual root cause.
- Avoid exists-then-chmod patterns without handling the deletion race.
- Prefer java.nio.file permission APIs where portability matters.
When it happens
Trigger: NativeIO.chmod(path, mode) on Windows where path is absent, misspelled, built with wrong separators/roots, or where the file was deleted between an exists() check and the chmod (TOCTOU race with a cleaner/concurrent task).
Common situations: Path construction bugs on Windows (drive letters, mixed separators, empty segments from null components); output-cleanup code racing a chmod; files already moved by another process.
Related errors
- UNKNOWN
- EBADF
- Could not rename temporary file {} to {} due to failure in n
- Not implemented for Windows
- Failed to set permissions of path: " + p + " to " + String.f
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/3e88f0c61468a89f.
Report an issue: GitHub.