{"record":{"id":"c806b0119de80fb0","repo":"apache/hadoop","slug":"file-is-empty-jsonfile","errorCode":null,"errorMessage":"File is empty: ${jsonFile}","messagePattern":"File is empty: (.+?)","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java","lineNumber":184,"sourceCode":"  /**\n   * Load from a JSON text file.\n   * @param jsonFile input file\n   * @return the parsed JSON\n   * @throws IOException IO problems\n   * @throws JsonParseException If the input is not well-formatted\n   * @throws JsonMappingException failure to map from the JSON to this class\n   */\n  @SuppressWarnings(\"unchecked\")\n  public synchronized T load(File jsonFile)\n      throws IOException, JsonParseException, JsonMappingException {\n    if (!jsonFile.exists()) {\n      throw new FileNotFoundException(\"No such file: \" + jsonFile);\n    }\n    if (!jsonFile.isFile()) {\n      throw new FileNotFoundException(\"Not a file: \" + jsonFile);\n    }\n    if (jsonFile.length() == 0) {\n      throw new EOFException(\"File is empty: \" + jsonFile);\n    }\n    try {\n      return mapper.readValue(jsonFile, classType);\n    } catch (IOException e) {\n      LOG.warn(\"Exception while parsing json file {}\", jsonFile, e);\n      throw e;\n    }\n  }\n\n  /**\n   * Save to a local file. Any existing file is overwritten unless\n   * the OS blocks that.\n   * @param file file\n   * @param instance instance\n   * @throws IOException IO exception\n   */\n  public void save(File file, T instance) throws\n      IOException {","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java#L166-L202","documentation":"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.","triggerScenarios":"Loading a zero-length file: a writer created the file and crashed before writing, or an external process truncated it.","commonSituations":"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.","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."],"exampleFix":"// before\nMyType t = serializer.load(stateFile);\n\n// after\nif (stateFile.length() == 0) {\n  return defaults(); // fresh install: no state written yet\n}\nreturn serializer.load(stateFile);","handlingStrategy":"validation","validationCode":"if (f.length() == 0) {\n  return defaults(); // or quarantine the file for investigation\n}\nreturn serializer.load(f);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["json","file","hadoop-common","empty-file"],"backgroundTag":"empty-file","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}