NationalSecurityAgency/ghidra · error · IOException

Could not find temporary directory

Error message

Could not find temporary directory

What it means

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.

Source

Thrown at Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/ingest/BulkSignatures.java:1019

		}
		else {
			exe = responseName.manage.findExecutable(query.spec.exename, query.spec.arch,
				query.spec.execompname);
		}
		String basename = "sigs_" + exe.getMd5();
		File sigFile = new File(resultFolder, basename);

		try (FileWriter writer = new FileWriter(sigFile)) {
			responseName.manage.saveXml(writer);
		}
	}

	protected File establishTemporaryDirectory(String xmldir) throws IOException {
		File dir;
		if (xmldir == null) {
			File tmpDir = Application.getUserTempDirectory();
			if (tmpDir == null) {
				throw new IOException("Could not find temporary directory");
			}
			dir = new File(tmpDir, "bulkinsert_xml");
			deleteTemporaryDirectory(dir);
		}
		else {
			dir = new File(xmldir);
		}
		if (dir.exists() == false) {
			if (dir.mkdir() == false) {
				throw new IOException("Unable to create temp directory: " + dir.getAbsolutePath());
			}
		}
		else if (dir.isDirectory() == false) {
			throw new IOException(dir.getAbsolutePath() + ": is not a directory");
		}
		dir = dir.getCanonicalFile();
		return dir;
	}

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Ensure Ghidra application initialization runs before any BSim ingest operation (call Application.initializeApplication in headless mode).
  2. Pass an explicit xmldir to establishTemporaryDirectory to bypass reliance on getUserTempDirectory.
  3. Verify java.io.tmpdir is set and writable: System.getProperty("java.io.tmpdir").
  4. In containers, ensure /tmp exists and is writable.

Example fix

// before
File tmpDir = Application.getUserTempDirectory();
if (tmpDir == null) {
    throw new IOException("Could not find temporary directory");
}

// after — fall back to system property
File tmpDir = Application.getUserTempDirectory();
if (tmpDir == null) {
    tmpDir = new File(System.getProperty("java.io.tmpdir"));
}
if (tmpDir == null || !tmpDir.isDirectory()) {
    throw new IOException("Could not find a valid temporary directory. " +
        "Set java.io.tmpdir or pass an explicit xmldir.");
}
Defensive patterns

Strategy: validation

Validate before calling

// Verify temp directory availability before calling establishTemporaryDirectory
File tmpDir = Application.getUserTempDirectory();
if (tmpDir == null) {
    // Fall back to system property
    String sysTmp = System.getProperty("java.io.tmpdir");
    if (sysTmp != null) {
        tmpDir = new File(sysTmp);
    }
}
if (tmpDir == null || !tmpDir.isDirectory()) {
    throw new IllegalStateException(
        "No valid temp directory available. Initialize Ghidra Application or pass xmldir.");
}

Type guard

public static boolean hasValidTempDirectory() {
    File tmpDir = Application.getUserTempDirectory();
    if (tmpDir != null && tmpDir.isDirectory()) return true;
    String sysTmp = System.getProperty("java.io.tmpdir");
    return sysTmp != null && new File(sysTmp).isDirectory();
}

Try / catch

try {
    File dir = bulk.establishTemporaryDirectory(null);
} catch (IOException e) {
    if (e.getMessage().contains("temporary directory")) {
        // Fall back to an explicit xmldir
        File dir = bulk.establishTemporaryDirectory("/tmp/bsim_work");
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/2f22a82c06f23f1b. Report an issue: GitHub.