apache/hadoop · error · EOFException
File is empty: ${jsonFile}
Error message
File is empty: ${jsonFile} What it means
load(File) throws EOFException("File is empty: <path>") when the file exists and is regular but has length 0. Hadoop checks this up front because Jackson's error for a zero-byte stream (a MismatchedInputException) hides the simple fact that there is nothing to parse.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java:184
/**
* Load from a JSON text file.
* @param jsonFile input file
* @return the parsed JSON
* @throws IOException IO problems
* @throws JsonParseException If the input is not well-formatted
* @throws JsonMappingException failure to map from the JSON to this class
*/
@SuppressWarnings("unchecked")
public synchronized T load(File jsonFile)
throws IOException, JsonParseException, JsonMappingException {
if (!jsonFile.exists()) {
throw new FileNotFoundException("No such file: " + jsonFile);
}
if (!jsonFile.isFile()) {
throw new FileNotFoundException("Not a file: " + jsonFile);
}
if (jsonFile.length() == 0) {
throw new EOFException("File is empty: " + jsonFile);
}
try {
return mapper.readValue(jsonFile, classType);
} catch (IOException e) {
LOG.warn("Exception while parsing json file {}", jsonFile, e);
throw e;
}
}
/**
* Save to a local file. Any existing file is overwritten unless
* the OS blocks that.
* @param file file
* @param instance instance
* @throws IOException IO exception
*/
public void save(File file, T instance) throws
IOException {View on GitHub (pinned to 2add963021)
Solutions
- Identify the writer that owns the file and regenerate it (re-run the job or restart the owning daemon).
- If empty files are a legitimate 'no state yet' case, check length() first and return defaults.
- Make the producer write atomically (temp file + rename) so empty files never appear at the final path.
Example fix
// before
MyType t = serializer.load(stateFile);
// after
if (stateFile.length() == 0) {
return defaults(); // fresh install: no state written yet
}
return serializer.load(stateFile); Defensive patterns
Strategy: validation
Validate before calling
if (f.length() == 0) {
return defaults(); // or quarantine the file for investigation
}
return serializer.load(f); Prevention
- Treat a zero-length state file as a writer crash until proven otherwise.
- Write files atomically (write temp, then rename) so partial or empty files never appear at the final name.
When it happens
Trigger: Loading a zero-length file: a writer created the file and crashed before writing, or an external process truncated it.
Common situations: State or metadata files left empty by an unclean shutdown; a file staged incompletely when a transfer was interrupted after create; placeholder files created by touch during setup.
Related errors
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/c806b0119de80fb0.
Report an issue: GitHub.