{"record":{"id":"63967c9b5a049e95","repo":"apache/hadoop","slug":"stat-is-not-supported-on-this-platform","errorCode":null,"errorMessage":"stat is not supported on this platform","messagePattern":"stat is not supported on this platform","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Stat.java","lineNumber":105,"sourceCode":"  FileStatus getFileStatusForTesting() {\n    return stat;\n  }\n\n  @Override\n  protected String[] getExecString() {\n    String derefFlag = \"-\";\n    if (dereference) {\n      derefFlag = \"-L\";\n    }\n    if (Shell.LINUX) {\n      return new String[] {\n          \"stat\", derefFlag + \"c\", \"%s,%F,%Y,%X,%a,%U,%G,%N\", path.toString() };\n    } else if (Shell.FREEBSD || Shell.MAC) {\n      return new String[] {\n          \"stat\", derefFlag + \"f\", \"%z,%HT,%m,%a,%Op,%Su,%Sg,`link' -> `%Y'\",\n          path.toString() };\n    } else {\n      throw new UnsupportedOperationException(\n          \"stat is not supported on this platform\");\n    }\n  }\n\n  @Override\n  protected void parseExecResult(BufferedReader lines) throws IOException {\n    // Reset stat\n    stat = null;\n\n    String line = lines.readLine();\n    if (line == null) {\n      throw new IOException(\"Unable to stat path: \" + original);\n    }\n    if (line.endsWith(\"No such file or directory\") ||\n        line.endsWith(\"Not a directory\")) {\n      throw new FileNotFoundException(\"File \" + original + \" does not exist\");\n    }\n    if (line.endsWith(\"Too many levels of symbolic links\")) {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Stat.java#L87-L123","documentation":"Thrown by org.apache.hadoop.fs.Stat when building the stat command: the class shells out to GNU/BSD 'stat' and only knows the flag sets for Linux, FreeBSD, and macOS (Shell.LINUX, Shell.FREEBSD, Shell.MAC). On any other platform - Windows, Solaris, AIX - there is no supported command line, so Stat throws UnsupportedOperationException from getStatCommand.","triggerScenarios":"Constructing org.apache.hadoop.fs.Stat (directly or via code paths that use it to fetch FileStatus) on Windows or any non-Linux/FreeBSD/macOS OS; running tests on a Windows developer box that exercise classes using Stat internally.","commonSituations":"Developer workstations on Windows; CI runners on unusual base images; edge code that still uses the legacy Stat wrapper instead of java.nio.file.Files.readAttributes.","solutions":["Run on a supported platform (Linux container) - the simplest fix for CI","Replace Stat usage with java.nio.file.Files.readAttributes(path, PosixFileAttributes.class), which is portable","Guard with Shell checks: only use Stat when Shell.LINUX || Shell.FREEBSD || Shell.MAC"],"exampleFix":"// before\nStat st = new Stat(path, false, shell).getFileStatus(); // throws on Windows\n\n// after\nimport java.nio.file.Files;\nimport java.nio.file.attribute.PosixFileAttributes;\nPosixFileAttributes attr = Files.readAttributes(\n    new java.io.File(path.toString()).toPath(), PosixFileAttributes.class);","handlingStrategy":"validation","validationCode":"import org.apache.hadoop.util.Shell;\nif (!(Shell.LINUX || Shell.FREEBSD || Shell.MAC)) {\n  // portable fallback; do not construct org.apache.hadoop.fs.Stat\n  java.nio.file.attribute.PosixFileAttributes a = java.nio.file.Files.readAttributes(\n      java.nio.file.Paths.get(path.toString()),\n      java.nio.file.attribute.PosixFileAttributes.class);\n}","typeGuard":null,"tryCatchPattern":"try {\n  new Stat(path, false, shell).getFileStatus();\n} catch (UnsupportedOperationException e) {\n  // \"stat is not supported on this platform\" -> use java.nio instead\n}","preventionTips":["Default to java.nio.file.Files.readAttributes for local FileStatus; treat Shell-based Stat as legacy","Run CI on Linux if the code path under test uses Stat internally"],"tags":["hadoop","stat","platform","unsupported-operation"],"backgroundTag":"unsupported-os-platform","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}