{"record":{"id":"6a2828af83d381d0","repo":"apache/hadoop","slug":"error-while-running-command-to-get-file-permission","errorCode":null,"errorMessage":"Error while running command to get file permissions : \" + StringUtils.stringifyException(e)","messagePattern":"Error while running command to get file permissions : \" \\+ StringUtils\\.stringifyException\\(e\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java","lineNumber":1122,"sourceCode":"        if (Shell.WINDOWS) {\n          owner = removeDomain(owner);\n          group = removeDomain(group);\n        }\n        setOwner(owner);\n        setGroup(group);\n      } catch (Shell.ExitCodeException ioe) {\n        if (ioe.getExitCode() != 1) {\n          e = ioe;\n        } else {\n          setPermission(null);\n          setOwner(null);\n          setGroup(null);\n        }\n      } catch (IOException ioe) {\n        e = ioe;\n      } finally {\n        if (e != null) {\n          throw new RuntimeException(\"Error while running command to get \" +\n                                     \"file permissions : \" + \n                                     StringUtils.stringifyException(e));\n        }\n      }\n    }\n\n    // In Windows, domain name is added.\n    // For example, given machine name (domain name) dname, user name i, then\n    // the result for user is dname\\\\i and for group is dname\\\\None. So we need\n    // remove domain name as follows:\n    // DOMAIN\\\\user => user, DOMAIN\\\\group => group\n    private String removeDomain(String str) {\n      int index = str.indexOf(\"\\\\\");\n      if (index != -1) {\n        str = str.substring(index + 1);\n      }\n      return str;\n    }","sourceCodeStart":1104,"sourceCodeEnd":1140,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java#L1104-L1140","documentation":"In the Windows permissions code path, RawLocalFileSystem runs a shell command (the 'ls' Stat helper) to read owner/group/permissions. If the command fails with an exit code other than 1, or the process I/O fails, the caught exception is rethrown as RuntimeException with the stringified cause. Exit code 1 is tolerated (fields nulled); any other failure — command not found, access denied spawning, hung/failed shell — escalates.","triggerScenarios":"getFileStatus on Windows when the helper command cannot run: Shell.RunCommand fails with ExitCodeException whose code != 1, cygwin/winutils missing so the command cannot be spawned, or an IOException while reading the process output; the finally block converts it to RuntimeException.","commonSituations":"Missing or mismatched winutils.exe/HADOOP_HOME on Windows, cygwin tools absent from PATH, permission changes preventing process execution, antivirus blocking the helper, or running on an unsupported Windows variant where the stat command behaves differently.","solutions":["Verify HADOOP_HOME and hadoop.dll/winutils.exe: point HADOOP_HOME at the matching Hadoop winutils build and put it on PATH.","Confirm the shell tools the stat command depends on exist (ls via cygwin or the bundled tools) and are executable by the process user.","Retry once on transient process spawn failures; escalate if persistent.","As a last resort on unsupported Windows environments, run the workload under WSL/Linux where the native path is used."],"exampleFix":"# before (shell, Windows)\n# HADOOP_HOME unset; java app calls getFileStatus -> RuntimeException from shell stat\n\n# after\nset HADOOP_HOME=C:\\hadoop\\hadoop-3.3.6\nset PATH=%HADOOP_HOME%\\bin;%PATH%\n# hadoop.dll present in HADOOP_HOME\\bin; app starts and stat succeeds","handlingStrategy":"try-catch","validationCode":"// startup sanity check on Windows before any FS ops\nString home = System.getenv(\"HADOOP_HOME\");\nif (home == null || !new java.io.File(home, \"bin/winutils.exe\").exists()) {\n  throw new IllegalStateException(\n      \"HADOOP_HOME/winutils.exe missing; local FS permission calls will fail\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  FileStatus st = fs.getFileStatus(p);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"file permissions\")) {\n    throw new IllegalStateException(\n        \"Windows stat helper failed; check HADOOP_HOME/winutils and PATH\", e);\n  }\n  throw e;\n}","preventionTips":["On Windows, install matching winutils.exe + hadoop.dll and set HADOOP_HOME/PATH before running.","Smoke-test with a trivial FileSystem.getFileStatus at application startup to fail early with a clear message.","Prefer WSL/Linux for workloads that hammer local-filesystem permission metadata."],"tags":["hadoop","local-filesystem","windows","shell","permissions","winutils","runtimeexception"],"backgroundTag":"shell-helper-command-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}