{"record":{"id":"17bb757de62cad00","repo":"stanfordnlp/CoreNLP","slug":"given-path-not-a-directory-path-dir-getabsolute","errorCode":null,"errorMessage":"Given path not a directory, path=\"+dir.getAbsolutePath()","messagePattern":"Given path not a directory, path=\"\\+dir\\.getAbsolutePath\\(\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java","lineNumber":850,"sourceCode":"    NodeList resourceNodes = doc.getElementsByTagName(SsurgeonPattern.RESOURCE_TAG);\n    for (int i=0; i < resourceNodes.getLength(); i++) {\n      Node node = patternNodes.item(i);\n      if (node.getNodeType() == Node.ELEMENT_NODE) {\n        Element resourceElt = (Element) node;\n        SsurgeonWordlist wlRsrc = new SsurgeonWordlist(resourceElt);\n        addResource(wlRsrc);\n      }\n    }\n\n    return retList;\n  }\n\n  /**\n   * Reads all Ssurgeon patterns from file.\n   * @throws Exception\n   */\n  public List<SsurgeonPattern> readFromDirectory(File dir) throws Exception {\n    if (!dir.isDirectory()) throw new Exception(\"Given path not a directory, path=\"+dir.getAbsolutePath());\n    if (VERBOSE)\n      System.out.println(\"Reading Ssurgeon patterns from directory = \"+dir.getAbsolutePath());\n    File[] files = dir.listFiles((dir1, name) -> name.toLowerCase().endsWith(\".xml\"));\n    List<SsurgeonPattern> patterns = new ArrayList<>();\n    for (File file : files) {\n      try {\n        patterns.addAll(readFromFile(file));\n      } catch (Exception e) {\n        log.error(e);\n      }\n    }\n    return patterns;\n  }\n\n  /**\n   * Given the root Element for a SemgrexPattern (SSURGEON_ELEM_TAG), converts\n   * it into its corresponding SemgrexPattern object.\n   */","sourceCodeStart":832,"sourceCodeEnd":868,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java#L832-L868","documentation":"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.","triggerScenarios":"Ssurgeon.readFromDirectory(dir) called with a File pointing at a regular file, a symlink to a file, or a path that does not exist.","commonSituations":"Configuration pointing at a single rules file where a directory is expected, or a typo'd/wrong path so isDirectory() returns false.","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"],"exampleFix":"// before\nssurgeon.readFromDirectory(new File(\"configs/rules.xml\"));\n// after\nFile dir = new File(\"configs/ssurgeon\");\nif (dir.isDirectory()) ssurgeon.readFromDirectory(dir);","handlingStrategy":"validation","validationCode":"// check before calling\njava.io.File dir = new java.io.File(path);\nif (!dir.isDirectory()) {\n  throw new IllegalArgumentException(\"Not a directory: \" + path);\n}","typeGuard":null,"tryCatchPattern":"try {\n  ssurgeon.readFromDirectory(dir);\n} catch (Exception e) {\n  log.severe(\"Bad ssurgeon directory: \" + dir + \" -> \" + e.getMessage());\n}","preventionTips":["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"],"tags":["java","filesystem","ssurgeon","path"],"backgroundTag":"path-is-not-a-directory","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"}