{"record":{"id":"efba0496f1a8a52e","repo":"apache/hadoop","slug":"is-not-a-directory-efba04","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/Delete.java","lineNumber":208,"sourceCode":"      \"[--ignore-fail-on-non-empty] <dir> ...\";\n    public static final String DESCRIPTION =\n      \"Removes the directory entry specified by each directory argument, \" +\n      \"provided it is empty.\\n\"; \n    \n    private boolean ignoreNonEmpty = false;\n    \n    @Override\n    protected void processOptions(LinkedList<String> args) throws IOException {\n      CommandFormat cf = new CommandFormat(\n          1, Integer.MAX_VALUE, \"-ignore-fail-on-non-empty\");\n      cf.parse(args);\n      ignoreNonEmpty = cf.getOpt(\"-ignore-fail-on-non-empty\");\n    }\n\n    @Override\n    protected void processPath(PathData item) throws IOException {\n      if (!item.stat.isDirectory()) {\n        throw new PathIsNotDirectoryException(item.toString());\n      }      \n      if (item.fs.listStatus(item.path).length == 0) {\n        if (!item.fs.delete(item.path, false)) {\n          throw new PathIOException(item.toString());\n        }\n      } else if (!ignoreNonEmpty) {\n        throw new PathIsNotEmptyDirectoryException(item.toString());\n      }\n    }\n  }\n\n  // delete files from the trash that are older\n  // than the retention threshold.\n  static class Expunge extends FsCommand {\n    private static final String OPTION_FILESYSTEM = \"fs\";\n\n    public static final String NAME = \"expunge\";\n    public static final String USAGE =","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Delete.java#L190-L226","documentation":"PathIsNotDirectoryException ('Is not a directory') thrown by Rmdir.processPath (Delete.java:208) when 'hadoop fs -rmdir' targets an existing path that is a regular file. rmdir is the POSIX-style 'remove empty directory only' command, so a file argument is rejected before listStatus/delete are attempted.","triggerScenarios":"'hadoop fs -rmdir /data/file.txt'; scripts that assume a path is a directory (e.g. a _SUCCESS-style marker that is actually a file); parameterized cleanup where $DIR sometimes names a file.","commonSituations":"Marker files confused with directories; porting 'rm -d' semantics; cleanup jobs iterating over a mix of files and dirs with a single command.","solutions":["Use 'hadoop fs -rm /data/file.txt' for files","Guard in scripts: 'hadoop fs -test -d /path && hadoop fs -rmdir /path || hadoop fs -rm /path'","Use 'hadoop fs -rm -r' when you want both files and directories removed uniformly"],"exampleFix":"# before\nhadoop fs -rmdir /job/_SUCCESS    # Is not a directory (_SUCCESS is a file)\n\n# after\nhadoop fs -rm /job/_SUCCESS","handlingStrategy":"validation","validationCode":"if (!fs.getFileStatus(path).isDirectory()) {\n  throw new PathIsNotDirectoryException(path.toString());\n}","typeGuard":"static boolean isEmptyableDirectory(FileSystem fs, Path p) throws IOException {\n  return fs.getFileStatus(p).isDirectory();\n}","tryCatchPattern":"try {\n  fs.delete(path, false);\n} catch (PathIsNotDirectoryException e) {\n  // it is a file: plain rm/delete is the correct command\n}","preventionTips":["Branch on 'hadoop fs -test -d' before rmdir in scripts","Use -rm for files, -rmdir strictly for empty directories","Use rm -r when uniform removal of mixed trees is wanted"],"tags":["hadoop","rmdir","shell","path-not-directory","argument-validation"],"backgroundTag":"path-not-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}