apache/hadoop · error · IOException
Unexpected empty line
Error message
Unexpected empty line
What it means
While parsing the second line of 'df' output, DF found no tokens at all (StringTokenizer.nextToken() threw NoSuchElementException, converted to IOException 'Unexpected empty line'). The data row DF picked was blank, so fields like filesystem/capacity/mount could not be extracted.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/DF.java:180
@VisibleForTesting
protected void parseOutput() throws IOException {
if (output.size() < 2) {
StringBuilder sb = new StringBuilder("Fewer lines of output than expected");
if (output.size() > 0) {
sb.append(": " + output.get(0));
}
throw new IOException(sb.toString());
}
String line = output.get(1);
StringTokenizer tokens =
new StringTokenizer(line, " \t\n\r\f%");
try {
this.filesystem = tokens.nextToken();
} catch (NoSuchElementException e) {
throw new IOException("Unexpected empty line");
}
if (!tokens.hasMoreTokens()) { // for long filesystem name
if (output.size() > 2) {
line = output.get(2);
} else {
throw new IOException("Expecting additional output after line: "
+ line);
}
tokens = new StringTokenizer(line, " \t\n\r\f%");
}
try {
Long.parseLong(tokens.nextToken()); // capacity
Long.parseLong(tokens.nextToken()); // used
Long.parseLong(tokens.nextToken()); // available
Integer.parseInt(tokens.nextToken()); // pct used
this.mount = tokens.nextToken();
} catch (NoSuchElementException e) {View on GitHub (pinned to 2add963021)
Solutions
- Run sudo -u <daemon> df -k <dir> and inspect the exact bytes (pipe through cat -A) to see the blank line.
- Set a standard locale for the daemon (LC_ALL=C in the systemd unit / container env) so df output formatting is stable.
- Replace any df shim/wrapper on the host with the stock coreutils binary; upgrade Hadoop for hardened DF parsing.
Example fix
# before # DF.parseOutput(): IOException: Unexpected empty line # after: pin locale for the daemon process # systemd unit: [Service] Environment=LC_ALL=C # verify: sudo -u hdfs df -k /grid/1/dn | cat -A (no blank data row)
Defensive patterns
Strategy: try-catch
Validate before calling
// detect a blank df data row before DF parses it // (run 'df -k <dir>' via ProcessBuilder and assert line 1 is non-blank)
Try / catch
try {
df.getMount();
} catch (IOException e) { // 'Unexpected empty line'
// fall back to java.io.File.getCanonicalPath/parent logic for mount detection
} Prevention
- Pin LC_ALL=C for daemons so df output has a stable layout.
- Avoid custom df wrappers/shims on hosts running Hadoop daemons.
- Add a df-output sanity check to node validation scripts.
When it happens
Trigger: DF.parseOutput() when output line index 1 is empty or whitespace-only: df emitting a blank line (some locales/plugins), interleaved stderr captured into stdout, or odd filesystems making df print a placeholder empty row.
Common situations: Non-POSIX locales or custom df wrappers in the image; FUSE/network mounts on old OSes whose df output has irregular blank lines; site-specific /usr/bin/df shim scripts.
Related errors
- Fewer lines of output than expected
- Expecting additional output after line: ${line}
- Could not parse line: ${line}
- Unexpected stat output: " + line
- value cannot be blank
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/f375668c34c669b2.
Report an issue: GitHub.