{"record":{"id":"3e88f0c61468a89f","repo":"apache/hadoop","slug":"enoent","errorCode":"ENOENT","errorMessage":"No such file or directory","messagePattern":"No such file or directory","errorType":"exception","errorClass":"NativeIOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/nativeio/NativeIO.java","lineNumber":398,"sourceCode":"     */\n    public static native FileDescriptor open(String path, int flags, int mode) throws IOException;\n    /** Wrapper around fstat(2) */\n    private static native Stat fstat(FileDescriptor fd) throws IOException;\n    /** Wrapper around stat(2). */\n    private static native Stat stat(String path) throws IOException;\n\n    /** Native chmod implementation. On UNIX, it is a wrapper around chmod(2) */\n    private static native void chmodImpl(String path, int mode) throws IOException;\n\n    public static void chmod(String path, int mode) throws IOException {\n      if (!Shell.WINDOWS) {\n        chmodImpl(path, mode);\n      } else {\n        try {\n          chmodImpl(path, mode);\n        } catch (NativeIOException nioe) {\n          if (nioe.getErrorCode() == 3) {\n            throw new NativeIOException(\"No such file or directory\",\n                Errno.ENOENT);\n          } else {\n            LOG.warn(String.format(\"NativeIO.chmod error (%d): %s\",\n                nioe.getErrorCode(), nioe.getMessage()));\n            throw new NativeIOException(\"Unknown error\", Errno.UNKNOWN);\n          }\n        }\n      }\n    }\n\n    /** Wrapper around posix_fadvise(2) */\n    static native void posix_fadvise(\n      FileDescriptor fd, long offset, long len, int flags) throws NativeIOException;\n\n    /** Wrapper around sync_file_range(2) */\n    static native void sync_file_range(\n      FileDescriptor fd, long offset, long nbytes, int flags) throws NativeIOException;\n","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/nativeio/NativeIO.java#L380-L416","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"Path p = Paths.get(path);\nif (!Files.exists(p)) {\n  // create the file first, or skip the chmod as nothing to do\n}","typeGuard":null,"tryCatchPattern":"try {\n  NativeIO.chmod(path, mode);\n} catch (NativeIOException e) {\n  if (e.getErrno() == Errno.ENOENT) {\n    // target already gone: benign if deleters race us, otherwise surface\n  } else { throw e; }\n}","preventionTips":["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."],"tags":["native-io","windows","chmod","enoent"],"backgroundTag":"enoent-file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}