{"record":{"id":"35d129c791265792","repo":"apache/hadoop","slug":"no-such-file-jsonfile","errorCode":null,"errorMessage":"No such file: ${jsonFile}","messagePattern":"No such file: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java","lineNumber":178,"sourceCode":"   * @throws JsonMappingException failure to map from the JSON to this class\n   */\n  public synchronized T fromJsonStream(InputStream stream) throws IOException {\n    return mapper.readValue(stream, classType);\n  }\n\n  /**\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.","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java#L160-L196","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nFile f = new File(\"state/nodes.json\");\nMyType t = serializer.load(f);\n\n// after\nFile f = new File(conf.get(\"app.state.dir\"), \"nodes.json\"); // absolute base from config\nif (!f.exists()) {\n  return defaults();\n}\nreturn serializer.load(f);","handlingStrategy":"validation","validationCode":"File f = new File(baseDir, name);\nif (!f.exists()) {\n  return defaults(); // or throw a domain exception naming the config key\n}\nreturn serializer.load(f);","typeGuard":null,"tryCatchPattern":"catch (FileNotFoundException e) {\n  // load() throws this only from its exists()/isFile() guards, before parsing\n}","preventionTips":["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."],"tags":["json","file","hadoop-common","configuration"],"backgroundTag":"file-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}