{"record":{"id":"21852e47f5b37796","repo":"apache/hadoop","slug":"unexpected-stat-output-line","errorCode":null,"errorMessage":"Unexpected stat output: \" + line","messagePattern":"Unexpected stat output: \" \\+ line","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Stat.java","lineNumber":166,"sourceCode":"      // 'notalink'\n      // `link' -> `target' OR 'link' -> 'target'\n      // '' -> ''\n      Path symlink = null;\n      String parts[] = symStr.split(\" -> \");      \n      try {\n        String target = parts[1];\n        target = target.substring(1, target.length()-1);\n        if (!target.isEmpty()) {\n          symlink = new Path(target);\n        }\n      } catch (ArrayIndexOutOfBoundsException e) {\n        // null if not a symlink\n      }\n      // Set stat\n      stat = new FileStatus(length, isDir, 1, blockSize, modTime, accessTime,\n          perms, owner, group, symlink, qualified);\n    } catch (NumberFormatException e) {\n      throw new IOException(\"Unexpected stat output: \" + line, e);\n    } catch (NoSuchElementException e) {\n      throw new IOException(\"Unexpected stat output: \" + line, e);\n    }\n  }\n}\n","sourceCodeStart":148,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Stat.java#L148-L172","documentation":"Thrown in Stat.parseExecResult when parsing the numeric CSV fields of stat output (size, mtime, atime, block size) raises NumberFormatException. The shell emitted a line that passed the error-string checks but is not the expected GNU/BSD numeric format, so Hadoop wraps the parse failure with the offending line for diagnosis.","triggerScenarios":"A locale or stat variant that formats numbers differently (localized output), a localized error message that does not match the hard-coded English 'No such file...' suffixes and falls through to parsing, or unexpected text (wrapper banner, SELinux audit noise) prepended to the line.","commonSituations":"Running with unusual LANG/LC_ALL settings; minimal container images shipping busybox or toybox stat whose output format differs from GNU coreutils; hosts where a site wrapper script replaces /usr/bin/stat.","solutions":["Run the exact command Stat builds (stat -c '%s,%F,%Y,%X,%a,%U,%G,%N' path) and compare with the expected CSV","Force a POSIX locale for the JVM process (LANG=C, LC_ALL=C) so number formatting is predictable","Replace Stat with java.nio.file.Files.readAttributes, which avoids shell parsing entirely"],"exampleFix":"// before: rely on shell `stat` parsing\nFileStatus st = new Stat(path, false, shell).getFileStatus();\n\n// after: locale-proof Java NIO\njava.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);","handlingStrategy":"try-catch","validationCode":"// deterministic formatting before relying on shell stat\n// launch the JVM with -Duser.language=en / LANG=C, LC_ALL=C\n// or skip the shell entirely:\njava.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);","typeGuard":null,"tryCatchPattern":"try {\n  st = stat.getFileStatus();\n} catch (IOException e) {\n  // \"Unexpected stat output: <line>\" -> inspect <line>: locale? non-GNU stat?\n  st = fallbackViaNio(path);\n}","preventionTips":["Pin LANG=C/LC_ALL=C in environments that shell out to stat","Verify GNU coreutils stat is the binary in PATH (no wrapper scripts, no busybox)"],"tags":["hadoop","stat","parsing","locale"],"backgroundTag":"shell-command-output-parse","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}