{"record":{"id":"1a87cc81b4a1f8ea","repo":"apache/hadoop","slug":"failed-to-read-json-file-e","errorCode":null,"errorMessage":"Failed to read JSON file ${e}","messagePattern":"Failed to read JSON file (.+?)","errorType":"exception","errorClass":"PathIOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java","lineNumber":280,"sourceCode":"   * @throws IOException IO problems\n   */\n  public T load(FileSystem fs, Path path, @Nullable FileStatus status)\n      throws IOException {\n\n    if (status != null && status.getLen() == 0) {\n      throw new EOFException(\"No data in \" + path);\n    }\n    FutureDataInputStreamBuilder builder = fs.openFile(path)\n        .opt(FS_OPTION_OPENFILE_READ_POLICY,\n            FS_OPTION_OPENFILE_READ_POLICY_WHOLE_FILE);\n    if (status != null) {\n      builder.withFileStatus(status);\n    }\n    try (FSDataInputStream dataInputStream =\n             awaitFuture(builder.build())) {\n      return fromJsonStream(dataInputStream);\n    } catch (JsonProcessingException e) {\n      throw new PathIOException(path.toString(),\n          \"Failed to read JSON file \" + e, e);\n    }\n  }\n\n  /**\n   * Save to a Hadoop filesystem.\n   * @param fs filesystem\n   * @param path path\n   * @param overwrite should any existing file be overwritten\n   * @param instance instance\n   * @throws IOException IO exception.\n   */\n  public void save(FileSystem fs, Path path, T instance,\n      boolean overwrite) throws\n      IOException {\n    writeJsonAsBytes(instance, fs.create(path, overwrite));\n  }\n","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java#L262-L298","documentation":"When the JSON read from an open FileSystem stream cannot be parsed, the Jackson JsonProcessingException is wrapped in PathIOException(path, \"Failed to read JSON file <cause>\", e). PathIOException identifies the offending path so callers can blame the file rather than the filesystem, and the cause chain keeps the exact Jackson error (line/column or mismatched property).","triggerScenarios":"load(fs, path, status) on a non-empty file whose bytes are not valid JSON for classType: truncated JSON, a different schema version, or a non-JSON file stored at the path.","commonSituations":"State file half-written by a crashed process (length > 0 but content truncated); schema drift after an upgrade changed the JSON shape; an error page or log file accidentally written to the expected path.","solutions":["Dump the file (hdfs dfs -cat) and validate it as JSON, comparing its shape with the target class.","Restore or regenerate the corrupted file - re-run the writer, or delete it so it is recreated from defaults.","Catch PathIOException in bulk-processing loops and quarantine the bad path instead of aborting the whole run."],"exampleFix":"// before\nfor (Path p : paths) {\n  items.add(serializer.load(fs, p, null)); // one bad file aborts everything\n}\n\n// after\nfor (Path p : paths) {\n  try {\n    items.add(serializer.load(fs, p, null));\n  } catch (PathIOException e) {\n    LOG.warn(\"Quarantining unparseable file {}\", p, e);\n    quarantine(p);\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  T v = serializer.load(fs, path, status);\n} catch (PathIOException e) {\n  // e.getPath() names the file; e.getCause() is the Jackson exception\n  // with line/column or the mismatched property\n}","preventionTips":["Never hand-edit JSON state files on the cluster; regenerate them with the owning tool.","Version state files (a schema field) so format drift is detectable before parsing fails."],"tags":["json","hdfs","hadoop-common","corrupt-file"],"backgroundTag":"malformed-json","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}