{"record":{"id":"98b01cf00b14ed0f","repo":"apache/hadoop","slug":"is-a-directory-98b01c","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/Head.java","lineNumber":66,"sourceCode":"  private long endingOffset = 1024;\n\n  @Override\n  protected void processOptions(LinkedList<String> args) throws IOException {\n    CommandFormat cf = new CommandFormat(1, 1);\n    cf.parse(args);\n  }\n\n  @Override\n  protected List<PathData> expandArgument(String arg) throws IOException {\n    List<PathData> items = new LinkedList<PathData>();\n    items.add(new PathData(arg, getConf()));\n    return items;\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    dumpToOffset(item);\n  }\n\n  private void dumpToOffset(PathData item) throws IOException {\n    try (FSDataInputStream in = item.openFile(\n        FS_OPTION_OPENFILE_READ_POLICY_SEQUENTIAL)) {\n      IOUtils.copyBytes(in, System.out, endingOffset, false);\n    }\n  }\n}\n","sourceCodeStart":48,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Head.java#L48-L79","documentation":"PathIsDirectoryException ('Is a directory') thrown by Head.processPath (Head.java:66) when 'hadoop fs -head' is applied to a directory. Head opens the path with the sequential read policy and copies only endingOffset bytes to stdout; a directory cannot be opened as a stream, so it is rejected before openFile().","triggerScenarios":"'hadoop fs -head /data/somedir'; peeking at a partition root; a script sanity-checking '$FILE' that actually points at a directory.","commonSituations":"Quick-peek workflows on generated data where users head the output dir instead of a part file; typo in the path dropping the file component; onboarding examples copied from cat/grep habits.","solutions":["Point at a file inside: 'hadoop fs -head /data/somedir/part-00000'","List first ('hadoop fs -ls /data/somedir') to pick the file to head","For structured data checks prefer 'hadoop fs -cat <file> | head -n 10' on a concrete part file","In code, gate on stat.isFile() before calling openFile()"],"exampleFix":"# before\nhadoop fs -head /events/dt=2026-08-21    # Is a directory\n\n# after\nhadoop fs -head /events/dt=2026-08-21/part-00000","handlingStrategy":"validation","validationCode":"if (item.stat.isDirectory()) {\n  throw new PathIsDirectoryException(item.toString());\n}","typeGuard":"static boolean isHeadableFile(FileStatus st) {\n  return st != null && st.isFile();\n}","tryCatchPattern":"try {\n  try (FSDataInputStream in = item.openFile(\n      FS_OPTION_OPENFILE_READ_POLICY_SEQUENTIAL)) {\n    IOUtils.copyBytes(in, System.out, endingOffset, false);\n  }\n} catch (PathIsDirectoryException e) {\n  // list the directory and head a specific part file\n}","preventionTips":["Head a concrete part file, not the output directory","-ls unfamiliar paths first when sanity-checking generated data","For samples of any file, cat a globbed part file and pipe to head"],"tags":["hadoop","head","shell","path-is-directory","argument-validation"],"backgroundTag":"path-is-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}