apache/hadoop · error · UnsupportedOperationException

stat is not supported on this platform

Error message

stat is not supported on this platform

What it means

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.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Stat.java:105

  FileStatus getFileStatusForTesting() {
    return stat;
  }

  @Override
  protected String[] getExecString() {
    String derefFlag = "-";
    if (dereference) {
      derefFlag = "-L";
    }
    if (Shell.LINUX) {
      return new String[] {
          "stat", derefFlag + "c", "%s,%F,%Y,%X,%a,%U,%G,%N", path.toString() };
    } else if (Shell.FREEBSD || Shell.MAC) {
      return new String[] {
          "stat", derefFlag + "f", "%z,%HT,%m,%a,%Op,%Su,%Sg,`link' -> `%Y'",
          path.toString() };
    } else {
      throw new UnsupportedOperationException(
          "stat is not supported on this platform");
    }
  }

  @Override
  protected void parseExecResult(BufferedReader lines) throws IOException {
    // Reset stat
    stat = null;

    String line = lines.readLine();
    if (line == null) {
      throw new IOException("Unable to stat path: " + original);
    }
    if (line.endsWith("No such file or directory") ||
        line.endsWith("Not a directory")) {
      throw new FileNotFoundException("File " + original + " does not exist");
    }
    if (line.endsWith("Too many levels of symbolic links")) {

View on GitHub (pinned to 2add963021)

Solutions

  1. Run on a supported platform (Linux container) - the simplest fix for CI
  2. Replace Stat usage with java.nio.file.Files.readAttributes(path, PosixFileAttributes.class), which is portable
  3. Guard with Shell checks: only use Stat when Shell.LINUX || Shell.FREEBSD || Shell.MAC

Example fix

// before
Stat st = new Stat(path, false, shell).getFileStatus(); // throws on Windows

// after
import java.nio.file.Files;
import java.nio.file.attribute.PosixFileAttributes;
PosixFileAttributes attr = Files.readAttributes(
    new java.io.File(path.toString()).toPath(), PosixFileAttributes.class);
Defensive patterns

Strategy: validation

Validate before calling

import org.apache.hadoop.util.Shell;
if (!(Shell.LINUX || Shell.FREEBSD || Shell.MAC)) {
  // portable fallback; do not construct org.apache.hadoop.fs.Stat
  java.nio.file.attribute.PosixFileAttributes a = java.nio.file.Files.readAttributes(
      java.nio.file.Paths.get(path.toString()),
      java.nio.file.attribute.PosixFileAttributes.class);
}

Try / catch

try {
  new Stat(path, false, shell).getFileStatus();
} catch (UnsupportedOperationException e) {
  // "stat is not supported on this platform" -> use java.nio instead
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/63967c9b5a049e95. Report an issue: GitHub.