{"record":{"id":"90c95af6d25adc56","repo":"apache/hadoop","slug":"failed-to-set-permissions-of-path-p-to","errorCode":null,"errorMessage":"Failed to set permissions of path: \" + p + \" to \" + String.format(\"%04o\", permission.toShort())","messagePattern":"Failed to set permissions of path: \" \\+ p \\+ \" to \" \\+ String\\.format\\(\"%04o\", permission\\.toShort\\(\\)\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java","lineNumber":1514,"sourceCode":"    if (group.implies(FsAction.WRITE) != user.implies(FsAction.WRITE)) {\n      rv = f.setWritable(user.implies(FsAction.WRITE), true);\n      checkReturnValue(rv, f, permission);\n    }\n\n    // exec perms\n    rv = f.setExecutable(group.implies(FsAction.EXECUTE), false);\n    checkReturnValue(rv, f, permission);\n    if (group.implies(FsAction.EXECUTE) != user.implies(FsAction.EXECUTE)) {\n      rv = f.setExecutable(user.implies(FsAction.EXECUTE), true);\n      checkReturnValue(rv, f, permission);\n    }\n  }\n\n  private static void checkReturnValue(boolean rv, File p,\n                                       FsPermission permission\n                                       ) throws IOException {\n    if (!rv) {\n      throw new IOException(\"Failed to set permissions of path: \" + p +\n                            \" to \" +\n                            String.format(\"%04o\", permission.toShort()));\n    }\n  }\n\n  private static void execSetPermission(File f,\n                                        FsPermission permission\n                                       )  throws IOException {\n    if (NativeIO.isAvailable()) {\n      NativeIO.POSIX.chmod(f.getCanonicalPath(), permission.toShort());\n    } else {\n      execCommand(f, Shell.getSetPermissionCommand(\n                  String.format(\"%04o\", permission.toShort()), false));\n    }\n  }\n\n  static String execCommand(File f, String... cmd) throws IOException {\n    String[] args = new String[cmd.length + 1];","sourceCodeStart":1496,"sourceCodeEnd":1532,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java#L1496-L1532","documentation":"checkReturnValue is used by FileUtil's pure-Java permission setter: it calls File.setReadable/Writable/Executable and if any returns false it throws IOException(\"Failed to set permissions of path: <p> to <octal>\") with the FsPermission rendered via String.format(\"%04o\", permission.toShort()). File.set* returns false (rather than throwing) when the operation is unsupported or disallowed — typically the caller is not the file's owner, or the filesystem does not implement POSIX mode bits.","triggerScenarios":"FileUtil.setPermission / setPermissions (non-NativeIO path) run by a user who does not own the file; filesystem without POSIX permissions (FAT32, some NTFS configurations, certain network/object mounts); attempting setuid/setsticky bits the java.io API cannot express (e.g. 1777 on /tmp-like dirs fails here).","commonSituations":"Services started as one user chowning/chmodding files created by another; Windows or exFAT data volumes; containers running as non-root against root-owned files; setting 01777-style permissions on staging dirs.","solutions":["Run the operation as the file's owner (or root) so File.set* is permitted","Pre-fix ownership with FileUtil.setOwner/fileSystem.setOwner, then apply permissions","Use a POSIX-compliant filesystem for paths whose permissions matter, and ensure NativeIO is available so the chmod path uses NativeIO.POSIX.chmod instead","Avoid permission bits java.io cannot represent (setuid/sticky) on this code path; use RawLocalFileSystem.setPermission if you need them"],"exampleFix":"// before\nFileUtil.setPermission(new File(\"/data/part-0\"),\n    FsPermission.valueOf(\"rw-r-----\")); // not owner -> IOException\n\n// after: chown first (as a permitted identity), then chmod\nFileUtil.setOwner(new File(\"/data/part-0\"), currentUser, null);\nFileUtil.setPermission(new File(\"/data/part-0\"),\n    FsPermission.valueOf(\"rw-r-----\"));","handlingStrategy":"try-catch","validationCode":"File f = new File(path);\nif (!f.canWrite()) throw new IOException(\"No write access to \" + f);\nif (!Files.isPosix(f.toPath().getFileSystem().supportedFileAttributeViews()\n        .contains(\"posix\"))) {\n  throw new IOException(\"POSIX permissions unsupported on this filesystem\");\n}","typeGuard":"static boolean canSetPosixPermissions(File f) throws IOException {\n  return f.getCanonicalFile().toPath().getFileSystem()\n      .supportedFileAttributeViews().contains(\"posix\");\n}","tryCatchPattern":"try {\n  FileUtil.setPermission(f, perm);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to set permissions\")) {\n    // not owner or non-POSIX fs: chown first as an authorized identity, or move\n    // the data to a POSIX filesystem and retry\n  } else throw e;\n}","preventionTips":["Run permission changes as the file owner or root","Keep permissioned data on POSIX filesystems where NativeIO is available","Avoid bits java.io cannot express (setuid/sticky) on this path"],"tags":["permissions","chmod","posix","not-owner","fileutil"],"backgroundTag":"permission-change-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}