SonarSource/sonarqube · error · IllegalStateException
Failed to create temp directory
Error message
Failed to create temp directory
What it means
DefaultTempFolder.createTempDir creates the backing temp directory with Files.createTempDirectory under the configured base dir. An IOException (permissions, missing parent, disk full) is wrapped in this IllegalStateException. The library throws it because the temp folder cannot function without its root directory.
Solutions
- Ensure the base temp directory's parent exists and is writable by the process user
- Fix java.io.tmpdir (or the configured temp path) to a writable location
- Check disk space and mount flags (read-only/tmpfs limits)
- Inspect e.getCause() for permission-denied details and adjust OS permissions/SELinux policy
Example fix
// before
Path base = Paths.get("/readonly/tmp");
DefaultTempFolder folder = new DefaultTempFolder(base, true);
// after
Path base = Paths.get("/var/tmp/sonar");
Files.createDirectories(base);
DefaultTempFolder folder = new DefaultTempFolder(base, true); Defensive patterns
Strategy: try-catch
Validate before calling
// ensure base dir is writable before constructing the temp folder
Path base = Paths.get(tempPath);
Files.createDirectories(base);
if (!Files.isWritable(base)) {
throw new IllegalStateException("temp base not writable: " + base);
} Try / catch
try {
return newDir(name);
} catch (IllegalStateException e) {
log.error("Temp dir creation failed: {}", e.getCause());
throw new IOException("Check temp base permissions/disk space", e);
} Prevention
- Point java.io.tmpdir at a writable, persistent location
- Ensure the service account owns/has write access to the temp path
- Monitor disk space and quotas on temp filesystems
- Recreate the DefaultTempFolder if an external process cleaned the base dir
When it happens
Trigger: Calling newDir()/newFile() construction path when the base temp directory cannot be created: parent missing, write permission denied, read-only filesystem, or disk full.
Common situations: java.io.tmpdir pointing to a read-only or non-existent location; running as a restricted service user; containers with tmpfs limits; SELinux/AppArmor blocking directory creation.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- "Failed to create temp directory - " + dir
- Can not delete
- Can not move file to
- Can not open file
- Can not unzip file to directory
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/0e575d99db10a18b.
Report an issue: GitHub.
Appendix: source
Thrown at sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/DefaultTempFolder.java:62
public DefaultTempFolder(File tempDir) {
this(tempDir, false);
}
public DefaultTempFolder(File tempDir, boolean deleteOnExit) {
this.tempDir = tempDir;
this.deleteOnExit = deleteOnExit;
}
@Override
public File newDir() {
return createTempDir(tempDir.toPath()).toFile();
}
private static Path createTempDir(Path baseDir) {
try {
return Files.createTempDirectory(baseDir, null);
} catch (IOException e) {
throw new IllegalStateException("Failed to create temp directory", e);
}
}
@Override
public File newDir(String name) {
File dir = new File(tempDir, name);
try {
FileUtils.forceMkdir(dir);
} catch (IOException e) {
throw new IllegalStateException("Failed to create temp directory - " + dir, e);
}
return dir;
}
@Override
public File newFile() {
return newFile(null, null);
}View on GitHub (pinned to 184c821202)