{"record":{"id":"e292e6afced8ddaa","repo":"apache/hadoop","slug":"is-not-a-directory-e292e6","errorCode":null,"errorMessage":"Is not a directory","messagePattern":"Is not a directory","errorType":"exception","errorClass":"PathIsNotDirectoryException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java","lineNumber":228,"sourceCode":"  protected enum FileTypeRequirement {\n    SHOULD_NOT_BE_DIRECTORY, SHOULD_BE_DIRECTORY\n  };\n\n  /**\n   * Ensure that the file exists and if it is or is not a directory\n   * @param typeRequirement Set it to the desired requirement.\n   * @throws PathIOException if file doesn't exist or the type does not match\n   * what was specified in typeRequirement.\n   */\n  private void checkIfExists(FileTypeRequirement typeRequirement) \n  throws PathIOException {\n    if (!exists) {\n      throw new PathNotFoundException(toString());      \n    }\n\n    if ((typeRequirement == FileTypeRequirement.SHOULD_BE_DIRECTORY)\n       && !stat.isDirectory()) {\n      throw new PathIsNotDirectoryException(toString());\n    } else if ((typeRequirement == FileTypeRequirement.SHOULD_NOT_BE_DIRECTORY)\n              && stat.isDirectory()) {\n      throw new PathIsDirectoryException(toString());\n    }\n  }\n  \n  /**\n   * Returns a new PathData with the given extension.\n   * @param extension for the suffix\n   * @return PathData\n   * @throws IOException shouldn't happen\n   */\n  public PathData suffix(String extension) throws IOException {\n    return new PathData(fs, this+extension);\n  }\n\n  /**\n   * Test if the parent directory exists","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java#L210-L246","documentation":"PathData.checkIfExists (PathData.java:228) throws PathIsNotDirectoryException ('Is not a directory') when the path exists, a SHOULD_BE_DIRECTORY requirement was requested, but stat.isDirectory() is false. All three in-class callers — getDirectoryContents(), getDirectoryContentsIterator(), getPathDataForChild() — pass SHOULD_BE_DIRECTORY, i.e. any shell operation that must read the path as a directory.","triggerScenarios":"'hadoop fs -ls /some/file' where the target exists as a regular file (ls of a bare file is fine via a different path, but directory-content listing hits this); a copy/move destination that exists as a file when getPathDataForChildPath tries to resolve children under it; passing a file where the API requires a directory source to enumerate.","commonSituations":"Destination path collision where a previous job left a file where a directory is expected; misconfigured output paths pointing at files; scripts assuming a path is a directory because a prior step 'should' have created it as one.","solutions":["Inspect the offending path: 'hadoop fs -ls <path>' — if it is a file, move or delete it","Correct the argument so it names a directory (add the missing subdirectory component)","In code, guard with 'if (!pd.stat.isDirectory())' or use fs.getFileStatus(path).isDirectory() before calling directory APIs"],"exampleFix":"# before\nhadoop fs -cp /src/* /out    # /out exists as a FILE -> Is not a directory\n\n# after\nhadoop fs -mv /out /out.file.bak\nhadoop fs -mkdir /out\nhadoop fs -cp /src/* /out/","handlingStrategy":"type-guard","validationCode":"FileStatus st = fs.getFileStatus(p);\nif (!st.isDirectory()) {\n  throw new IllegalStateException(\"expected directory: \" + p);\n}","typeGuard":"boolean isUsableDir(FileSystem fs, Path p) throws IOException {\n  FileStatus st = fs.getFileStatus(p);\n  return st.isDirectory();\n}","tryCatchPattern":"catch (PathIsNotDirectoryException e) { relocate the conflicting file, mkdir the directory, then retry the operation }","preventionTips":["Use 'hadoop fs -test -d' guards in scripts","Never assume a path's type from a previous run","Keep output-path ownership consistent across pipeline runs"],"tags":["path-is-not-directory","type-mismatch","pathdata","hadoop-shell"],"backgroundTag":"path-is-not-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}