apache/hadoop · error · FileNotFoundException
No such file: ${jsonFile}
Error message
No such file: ${jsonFile} What it means
JsonSerialization.load(File) validates the path before parsing: when File.exists() is false it throws FileNotFoundException("No such file: <path>"). The explicit pre-check distinguishes a missing file from a JSON parse failure and reports the exact path the JVM saw.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java:178
* @throws JsonMappingException failure to map from the JSON to this class
*/
public synchronized T fromJsonStream(InputStream stream) throws IOException {
return mapper.readValue(stream, classType);
}
/**
* 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.View on GitHub (pinned to 2add963021)
Solutions
- Log file.getAbsolutePath() and compare it with the real location of the file.
- Use an absolute path or resolve against an explicitly configured base directory.
- If absence is legitimate (first run), check exists() first and initialize defaults instead of loading.
Example fix
// before
File f = new File("state/nodes.json");
MyType t = serializer.load(f);
// after
File f = new File(conf.get("app.state.dir"), "nodes.json"); // absolute base from config
if (!f.exists()) {
return defaults();
}
return serializer.load(f); Defensive patterns
Strategy: validation
Validate before calling
File f = new File(baseDir, name);
if (!f.exists()) {
return defaults(); // or throw a domain exception naming the config key
}
return serializer.load(f); Try / catch
catch (FileNotFoundException e) {
// load() throws this only from its exists()/isFile() guards, before parsing
} Prevention
- Derive file paths from configuration or an absolute base dir, never from the current working directory.
- Fail fast at startup on missing required state files, naming the config key in the message.
When it happens
Trigger: Calling load(new File(p)) where p does not exist on the filesystem the process sees: a relative path resolved against the wrong working directory, a typo, or a file that was never written.
Common situations: Daemon started from a different working directory so a relative state-file path resolves elsewhere; fresh cluster where the state file was never created; path assembled by string concatenation with a missing '/' separator.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Not a file: ${jsonFile}
- File is empty: ${jsonFile}
- Errors on getting mount table loader class. The fs.viewfs.mo
- %s=null: %s: %s
- Codec not configured for custom codec {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/35d129c791265792.
Report an issue: GitHub.