{"record":{"id":"2f22a82c06f23f1b","repo":"NationalSecurityAgency/ghidra","slug":"could-not-find-temporary-directory","errorCode":null,"errorMessage":"Could not find temporary directory","messagePattern":"Could not find temporary directory","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java","lineNumber":1019,"sourceCode":"\t\t}\n\t\telse {\n\t\t\texe = responseName.manage.findExecutable(query.spec.exename, query.spec.arch,\n\t\t\t\tquery.spec.execompname);\n\t\t}\n\t\tString basename = \"sigs_\" + exe.getMd5();\n\t\tFile sigFile = new File(resultFolder, basename);\n\n\t\ttry (FileWriter writer = new FileWriter(sigFile)) {\n\t\t\tresponseName.manage.saveXml(writer);\n\t\t}\n\t}\n\n\tprotected File establishTemporaryDirectory(String xmldir) throws IOException {\n\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}","sourceCodeStart":1001,"sourceCodeEnd":1037,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java#L1001-L1037","documentation":"Thrown by establishTemporaryDirectory when Application.getUserTempDirectory() returns null. This is a Ghidra application environment failure — the temp directory path could not be resolved. This usually means the Ghidra application was not properly initialized before this code runs.","triggerScenarios":"Calling establishTemporaryDirectory when xmldir is null (the common path) and the Ghidra Application layer has not been initialized, or the system temp directory property is unset/inaccessible. Application.getUserTempDirectory() relies on Ghidra's application initialization having completed.","commonSituations":"Running BSim command-line tools without calling Application.initializeApplication first; the java.io.tmpdir system property is unset or points to a non-existent path; running in a sandboxed/containerized environment where temp directory setup failed; running headless without proper Ghidra application layout.","solutions":["Ensure Ghidra application initialization runs before any BSim ingest operation (call Application.initializeApplication in headless mode).","Pass an explicit xmldir to establishTemporaryDirectory to bypass reliance on getUserTempDirectory.","Verify java.io.tmpdir is set and writable: System.getProperty(\"java.io.tmpdir\").","In containers, ensure /tmp exists and is writable."],"exampleFix":"// before\nFile tmpDir = Application.getUserTempDirectory();\nif (tmpDir == null) {\n    throw new IOException(\"Could not find temporary directory\");\n}\n\n// after — fall back to system property\nFile tmpDir = Application.getUserTempDirectory();\nif (tmpDir == null) {\n    tmpDir = new File(System.getProperty(\"java.io.tmpdir\"));\n}\nif (tmpDir == null || !tmpDir.isDirectory()) {\n    throw new IOException(\"Could not find a valid temporary directory. \" +\n        \"Set java.io.tmpdir or pass an explicit xmldir.\");\n}","handlingStrategy":"validation","validationCode":"// Verify temp directory availability before calling establishTemporaryDirectory\nFile tmpDir = Application.getUserTempDirectory();\nif (tmpDir == null) {\n    // Fall back to system property\n    String sysTmp = System.getProperty(\"java.io.tmpdir\");\n    if (sysTmp != null) {\n        tmpDir = new File(sysTmp);\n    }\n}\nif (tmpDir == null || !tmpDir.isDirectory()) {\n    throw new IllegalStateException(\n        \"No valid temp directory available. Initialize Ghidra Application or pass xmldir.\");\n}","typeGuard":"public static boolean hasValidTempDirectory() {\n    File tmpDir = Application.getUserTempDirectory();\n    if (tmpDir != null && tmpDir.isDirectory()) return true;\n    String sysTmp = System.getProperty(\"java.io.tmpdir\");\n    return sysTmp != null && new File(sysTmp).isDirectory();\n}","tryCatchPattern":"try {\n    File dir = bulk.establishTemporaryDirectory(null);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"temporary directory\")) {\n        // Fall back to an explicit xmldir\n        File dir = bulk.establishTemporaryDirectory(\"/tmp/bsim_work\");\n    } else {\n        throw e;\n    }\n}","preventionTips":["Ensure Ghidra Application.initializeApplication runs before BSim operations.","In containers, verify /tmp exists and is writable.","Pass an explicit xmldir to bypass reliance on Application.getUserTempDirectory.","Set java.io.tmpdir explicitly when running headless."],"tags":["bsim","environment","temp-directory","ghidra-init"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}