{"record":{"id":"e6ad98215c7b24fc","repo":"stanfordnlp/CoreNLP","slug":"directory-access-problem-for-path","errorCode":null,"errorMessage":"Directory access problem for: ${path}","messagePattern":"Directory access problem for: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/FileSequentialCollection.java","lineNumber":338,"sourceCode":"              // this directory is finished and we pop up\n              fileArrayStack.pop();\n            }\n          } else {\n            // take it off the stack: tail recursion optimization\n            fileArrayStack.pop();\n            if (obj instanceof String) {\n              obj = new File((String) obj);\n            }\n            if (!(obj instanceof File)) {\n              throw new IllegalArgumentException(\"Collection elements must be Files or Strings\");\n            }\n            File path = (File) obj;\n            if (path.isDirectory()) {\n              // log.info(\"Got directory \" + path);\n              // if path is a directory, look into it\n              File[] directoryListing = path.listFiles(filt);\n              if (directoryListing == null) {\n                throw new IllegalArgumentException(\"Directory access problem for: \" + path);\n              }\n              // log.info(\"  with \" +\n              //\t    directoryListing.length + \" files in it.\");\n              if (includeDirs) {\n                // log.info(\"Include dir as answer\");\n                if (directoryListing.length > 0) {\n                  fileArrayStack.push(directoryListing);\n                  fileArrayStackIndices.push(Integer.valueOf(0));\n                }\n                return path;\n              } else {\n                // we don't include the dir, so we'll push\n                // the directory and loop around again ...\n                if (directoryListing.length > 0) {\n                  fileArrayStack.push(directoryListing);\n                  fileArrayStackIndices.push(Integer.valueOf(0));\n                }\n                // otherwise there was nothing in the","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/FileSequentialCollection.java#L320-L356","documentation":"When primeNextFile encounters a directory it calls File.listFiles(filt); a null return means the directory could not be read (I/O error, permissions, race deletion). The class surfaces this as IllegalArgumentException naming the offending path.","triggerScenarios":"Iterating a FileSequentialCollection whose seed path is a directory that listFiles() cannot enumerate: unreadable directory, deleted between checks, or path is not actually a readable directory on that filesystem.","commonSituations":"Running without read/execute permission on a data directory; NFS mounts dropping; directory removed by another process during iteration; typos producing a pseudo-directory path; sandboxed/containers denying access.","solutions":["Verify the process has read+execute permission on the directory (ls -ld path; chmod/chown as needed).","Confirm the directory exists and is a real directory before constructing the collection (path.isDirectory()).","Check for external deletion or remounting; re-check mount status and logs.","Run outside sandbox/SELinux/AppArmor restrictions or adjust policy to allow directory listing."],"exampleFix":"// before\nnew FileSequentialCollection(files, filter, false); // files contains unreadable dir\n// after\nFile dir = new File(\"/data/corpus\");\nif (!dir.isDirectory() || !dir.canRead()) throw new IllegalStateException(\"Unreadable dir: \" + dir);\nnew FileSequentialCollection(files, filter, false);","handlingStrategy":"validation","validationCode":"File dir = new File(path);\nif (!dir.isDirectory() || !dir.canRead() || dir.listFiles() == null) {\n  throw new IllegalStateException(\"Cannot list directory: \" + dir);\n}","typeGuard":"boolean isListableDir(File d) {\n  return d.isDirectory() && d.canRead() && d.listFiles() != null;\n}","tryCatchPattern":"try {\n  for (File f : new FileSequentialCollection(seeds, filt, includeDirs)) { process(f); }\n} catch (IllegalArgumentException e) {\n  log.severe(\"Directory listing failed: \" + e.getMessage());\n}","preventionTips":["Check isDirectory() and canRead() on seed paths before iterating","Run the JVM with a user that owns or can read the data directories","Avoid deleting directories while a collection is being iterated"],"tags":["file-io","permissions","directory"],"backgroundTag":"permission-denied","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}