stanfordnlp/CoreNLP · error · Exception
Given path not a directory, path="+dir.getAbsolutePath()
Error message
Given path not a directory, path="+dir.getAbsolutePath()
What it means
readFromDirectory loads all .xml ssurgeon pattern files from a directory. It first checks that the given File is actually a directory; a plain file path or nonexistent path (isDirectory() false) triggers a plain java Exception (not SsurgeonParseException) with this message.
Solutions
- Pass a File that is an existing directory containing .xml ssurgeon files
- Check the path exists and is a directory before calling (dir.exists() && dir.isDirectory())
- Use readFromFile instead if you have a single XML rules file
Example fix
// before
ssurgeon.readFromDirectory(new File("configs/rules.xml"));
// after
File dir = new File("configs/ssurgeon");
if (dir.isDirectory()) ssurgeon.readFromDirectory(dir); Defensive patterns
Strategy: validation
Validate before calling
// check before calling
java.io.File dir = new java.io.File(path);
if (!dir.isDirectory()) {
throw new IllegalArgumentException("Not a directory: " + path);
} Try / catch
try {
ssurgeon.readFromDirectory(dir);
} catch (Exception e) {
log.severe("Bad ssurgeon directory: " + dir + " -> " + e.getMessage());
} Prevention
- Validate the path is an existing directory before calling
- Distinguish single-file (readFromFile) vs directory (readFromDirectory) config options
- Fail fast at config load time by probing the directory
When it happens
Trigger: Ssurgeon.readFromDirectory(dir) called with a File pointing at a regular file, a symlink to a file, or a path that does not exist.
Common situations: Configuration pointing at a single rules file where a directory is expected, or a typo'd/wrong path so isDirectory() returns false.
Related errors
- cp: cannot copy to directory
- Cannot combine MWT out of only
- Cannot make a KillAllIncomingEdges out of " +…
- Cannot make a Lemmatize with no nodeName
- Cannot make a MergeNodes out of fewer than 2 nodes (got " +…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/17bb757de62cad00.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java:850
NodeList resourceNodes = doc.getElementsByTagName(SsurgeonPattern.RESOURCE_TAG);
for (int i=0; i < resourceNodes.getLength(); i++) {
Node node = patternNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element resourceElt = (Element) node;
SsurgeonWordlist wlRsrc = new SsurgeonWordlist(resourceElt);
addResource(wlRsrc);
}
}
return retList;
}
/**
* Reads all Ssurgeon patterns from file.
* @throws Exception
*/
public List<SsurgeonPattern> readFromDirectory(File dir) throws Exception {
if (!dir.isDirectory()) throw new Exception("Given path not a directory, path="+dir.getAbsolutePath());
if (VERBOSE)
System.out.println("Reading Ssurgeon patterns from directory = "+dir.getAbsolutePath());
File[] files = dir.listFiles((dir1, name) -> name.toLowerCase().endsWith(".xml"));
List<SsurgeonPattern> patterns = new ArrayList<>();
for (File file : files) {
try {
patterns.addAll(readFromFile(file));
} catch (Exception e) {
log.error(e);
}
}
return patterns;
}
/**
* Given the root Element for a SemgrexPattern (SSURGEON_ELEM_TAG), converts
* it into its corresponding SemgrexPattern object.
*/View on GitHub (pinned to 1b7edd19c4)