apache/hadoop · error · FileNotFoundException

Not a file: ${jsonFile}

Error message

Not a file: ${jsonFile}

What it means

load(File) requires a regular file: when the path exists but isFile() is false (a directory, device, or special file) it throws FileNotFoundException("Not a file: <path>"). The guard keeps Jackson from trying to stream a directory, whose error would be far less clear.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java:181

    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.
   * @param file file
   * @param instance instance
   * @throws IOException IO exception

View on GitHub (pinned to 2add963021)

Solutions

  1. Inspect the path (ls -ld) and correct the property or argument to name the actual JSON file.
  2. Fix path construction so the filename is always appended to the directory component.
  3. Add an isFile() check upstream that raises an error naming the offending setting.

Example fix

// before
File f = new File(conf.get("metadata.dir")); // points at the directory
MyType t = serializer.load(f);

// after
File f = new File(conf.get("metadata.dir"), "metadata.json");
return serializer.load(f);
Defensive patterns

Strategy: validation

Validate before calling

if (!f.isFile()) {
  throw new IllegalArgumentException(
      "Configured path is not a regular file: " + f.getAbsolutePath());
}
return serializer.load(f);

Prevention

When it happens

Trigger: Passing a directory to load(): a config property pointing at the directory that contains the JSON instead of the file, or a path built with the filename component dropped.

Common situations: Property set to /etc/hadoop/conf while the code expects /etc/hadoop/conf/file.json; glob or variable expansion returning the parent directory; a CLI flag where the user passed the folder.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/63fbacf95362c05f. Report an issue: GitHub.