apache/hadoop · error · EOFException
No data
Error message
No data
What it means
JsonSerialization.fromJson(String) parses a caller-supplied string into the parameterized type. Before handing the string to Jackson it rejects the empty string with EOFException("No data"), because Jackson's own failure for an empty document (MismatchedInputException 'No content to map') does not make clear that the input was simply empty.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java:144
*/
public ObjectMapper getMapper() {
return mapper;
}
/**
* Convert from JSON.
*
* @param json input
* @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 fromJson(String json)
throws IOException, JsonParseException, JsonMappingException {
if (json.isEmpty()) {
throw new EOFException("No data");
}
try {
return mapper.readValue(json, classType);
} catch (IOException e) {
LOG.error("Exception while parsing json : {}\n{}", e, json, e);
throw e;
}
}
/**
* Read from an input stream.
* @param stream stream to read from
* @return the parsed entity
* @throws IOException IO problems
* @throws JsonParseException If the input is not well-formatted
* @throws JsonMappingException failure to map from the JSON to this class
*/
public synchronized T fromJsonStream(InputStream stream) throws IOException {View on GitHub (pinned to 2add963021)
Solutions
- Treat the empty string as an upstream data-production failure: log where the string came from - the parse is never the real problem.
- Guard the call: if 'no data' is a legitimate state, skip parsing or return a default instead of calling fromJson.
- Regenerate the empty input (re-run the job or daemon that was supposed to write it).
Example fix
// before String json = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); MyType t = serializer.fromJson(json); // EOFException: No data when file is empty // after String json = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); MyType t = (json == null || json.isEmpty()) ? null : serializer.fromJson(json);
Defensive patterns
Strategy: validation
Validate before calling
if (json == null || json.isEmpty()) {
// no data: skip parsing, return default, or report the upstream writer
return null;
}
return serializer.fromJson(json); Try / catch
try {
T v = serializer.fromJson(json);
} catch (EOFException e) {
// fromJson throws EOFException("No data") only for empty input
} Prevention
- Check input length before reading a file into a string for JSON parsing.
- Treat an empty payload as a writer failure and log the source path/endpoint.
- Centralize 'empty means absent' handling instead of scattering isEmpty checks.
When it happens
Trigger: Calling serializer.fromJson("") - typically the string was produced by reading a file or response body that contained no data, or by a serialization step that emitted nothing.
Common situations: A config/state file that exists but is empty after an interrupted write; an HTTP response body that arrived empty; test fixtures passing an empty string where JSON is expected.
Related errors
- Failed to parse JSON
- No such file: ${jsonFile}
- Not a file: ${jsonFile}
- File is empty: ${jsonFile}
- ${resource}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/6198ead218a6c1c3.
Report an issue: GitHub.