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

  1. Pass a File that is an existing directory containing .xml ssurgeon files
  2. Check the path exists and is a directory before calling (dir.exists() && dir.isDirectory())
  3. 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

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


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)