{"record":{"id":"2cc5145751659d34","repo":"apache/hadoop","slug":"is-a-directory-2cc514","errorCode":null,"errorMessage":"Is a directory","messagePattern":"Is a directory","errorType":"exception","errorClass":"PathIsDirectoryException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Display.java","lineNumber":91,"sourceCode":"    public static final String USAGE = \"[-ignoreCrc] <src> ...\";\n    public static final String DESCRIPTION =\n      \"Fetch all files that match the file pattern <src> \" +\n      \"and display their content on stdout.\\n\";\n\n    private boolean verifyChecksum = true;\n\n    @Override\n    protected void processOptions(LinkedList<String> args)\n    throws IOException {\n      CommandFormat cf = new CommandFormat(1, Integer.MAX_VALUE, \"ignoreCrc\");\n      cf.parse(args);\n      verifyChecksum = !cf.getOpt(\"ignoreCrc\");\n    }\n\n    @Override\n    protected void processPath(PathData item) throws IOException {\n      if (item.stat.isDirectory()) {\n        throw new PathIsDirectoryException(item.toString());\n      }\n      \n      item.fs.setVerifyChecksum(verifyChecksum);\n      printToStdout(getInputStream(item));\n    }\n\n    private void printToStdout(InputStream in) throws IOException {\n      try {\n        IOUtils.copyBytes(in, out, getConf(), false);\n      } finally {\n        in.close();\n      }\n    }\n\n    protected InputStream getInputStream(PathData item) throws IOException {\n      // Always do sequential reads;\n      return item.openForSequentialIO();\n    }","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Display.java#L73-L109","documentation":"PathIsDirectoryException ('Is a directory') thrown by Cat.processPath (Display.java:91) when 'hadoop fs -cat' is applied to a directory. cat copies bytes of a single file to stdout (after optionally toggling checksum verification via -ignoreCrc), and a directory has no byte stream, so the shell rejects it per-path before opening.","triggerScenarios":"'hadoop fs -cat /data/somedir'; an unquoted glob that matched nothing leaving a literal directory arg; passing a partition root (e.g. /table/dt=2026-01-01) that is a directory.","commonSituations":"Inspecting Hive/Spark partition paths where the partition is a directory of part files; quick data checks that assume a file but the path is a directory; piping 'hadoop fs -cat $P' with P pointing at a directory.","solutions":["Glob the files inside: 'hadoop fs -cat \"/data/somedir/*\"' (quote so Hadoop, not the shell, expands it)","Or target a specific file: 'hadoop fs -cat /data/somedir/part-00000'","For a quick size/structure look, use 'hadoop fs -ls /data/somedir' first","For partitioned data, iterate the part files or use 'hadoop fs -getmerge' to a local file"],"exampleFix":"# before\nhadoop fs -cat /table/dt=2026-01-01     # Is a directory\n\n# after\nhadoop fs -cat '/table/dt=2026-01-01/*'","handlingStrategy":"validation","validationCode":"if (item.stat.isDirectory()) {\n  throw new PathIsDirectoryException(item.toString());\n}","typeGuard":"static boolean isReadableFile(FileStatus st) {\n  return st != null && st.isFile();\n}","tryCatchPattern":"try {\n  IOUtils.copyBytes(item.openFile(), out, conf);\n} catch (PathIsDirectoryException e) {\n  // glob the directory's files and cat those instead\n}","preventionTips":["Point cat at files or quoted globs ('/dir/*'), never partition roots","Validate with -ls before catting unfamiliar paths","For partitions, iterate part files or use getmerge"],"tags":["hadoop","cat","shell","path-is-directory","argument-validation"],"backgroundTag":"path-is-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}