{"record":{"id":"dcea394ad56d0585","repo":"NationalSecurityAgency/ghidra","slug":"dir-getabsolutepath-is-not-a-directory","errorCode":null,"errorMessage":"{dir.getAbsolutePath()}: is not a directory","messagePattern":"(.+?): is not a directory","errorType":"validation","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java","lineNumber":1033,"sourceCode":"\t\tFile dir;\n\t\tif (xmldir == null) {\n\t\t\tFile tmpDir = Application.getUserTempDirectory();\n\t\t\tif (tmpDir == null) {\n\t\t\t\tthrow new IOException(\"Could not find temporary directory\");\n\t\t\t}\n\t\t\tdir = new File(tmpDir, \"bulkinsert_xml\");\n\t\t\tdeleteTemporaryDirectory(dir);\n\t\t}\n\t\telse {\n\t\t\tdir = new File(xmldir);\n\t\t}\n\t\tif (dir.exists() == false) {\n\t\t\tif (dir.mkdir() == false) {\n\t\t\t\tthrow new IOException(\"Unable to create temp directory: \" + dir.getAbsolutePath());\n\t\t\t}\n\t\t}\n\t\telse if (dir.isDirectory() == false) {\n\t\t\tthrow new IOException(dir.getAbsolutePath() + \": is not a directory\");\n\t\t}\n\t\tdir = dir.getCanonicalFile();\n\t\treturn dir;\n\t}\n\n\tprivate void deleteTemporaryDirectory(File tempDir) throws IOException {\n\t\tif (!tempDir.exists()) {\n\t\t\treturn;\n\t\t}\n\t\tFile[] listFiles = tempDir.listFiles();\n\t\tif (listFiles == null) {\n\t\t\tthrow new IOException(\n\t\t\t\t\"Could not list files in temp directory: \" + tempDir.getAbsolutePath());\n\t\t}\n\t\tfor (File listFile : listFiles) {\n\t\t\tif (!listFile.delete()) {\n\t\t\t\tthrow new IOException(\n\t\t\t\t\t\"Unable to delete temporary file: \" + listFile.getAbsolutePath());","sourceCodeStart":1015,"sourceCodeEnd":1051,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java#L1015-L1051","documentation":"Thrown by establishTemporaryDirectory when the target path exists (dir.exists() is true) but is not a directory (dir.isDirectory() is false). This means a regular file occupies the path that should be a directory. The code cannot proceed because it needs to write files into this directory.","triggerScenarios":"A previous process or manual operation created a regular file at the path where the code expects a directory. This is the else-if branch after the mkdir path, so the path already exists as something other than a directory.","commonSituations":"A prior failed run left a file named 'bulkinsert_xml' instead of a directory; a user accidentally created a file with the same name; the xmldir parameter points to a path occupied by a file; a symlink pointing to a file rather than a directory.","solutions":["Remove or rename the file at the conflicting path.","Change the xmldir parameter to point to a valid directory location.","If using the default temp path, remove the stray file from the temp directory manually.","Investigate what created the file — it may indicate a bug in a prior step."],"exampleFix":"// before\nelse if (dir.isDirectory() == false) {\n    throw new IOException(dir.getAbsolutePath() + \": is not a directory\");\n}\n\n// after — distinguish file vs symlink vs other\nelse if (dir.isDirectory() == false) {\n    throw new IOException(dir.getAbsolutePath() + \": exists as a \" +\n        (dir.isFile() ? \"regular file\" : \"non-directory entry\") +\n        \"; remove it or specify a different xmldir\");\n}","handlingStrategy":"validation","validationCode":"// Check that the path is not occupied by a non-directory entry\nif (dir.exists() && !dir.isDirectory()) {\n    throw new IllegalStateException(\n        \"Path occupied by non-directory entry: \" + dir.getAbsolutePath() +\n        \". Remove it or use a different path.\");\n}","typeGuard":"public static boolean isPathAvailableForDirectory(File dir) {\n    return !dir.exists() || dir.isDirectory();\n}","tryCatchPattern":"try {\n    File dir = bulk.establishTemporaryDirectory(xmldir);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"is not a directory\")) {\n        // The path is a file — try removing it or use alternate location\n        File conflict = new File(xmldir);\n        if (conflict.isFile()) {\n            conflict.delete();\n        }\n        File dir = bulk.establishTemporaryDirectory(xmldir);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Check for file-vs-directory conflicts at the target path before running.","Clean up stale temp directories between runs.","Use unique temp directory names per run to avoid conflicts.","Verify the xmldir parameter points to a directory, not a file."],"tags":["bsim","file-io","temp-directory","conflict"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}