{"record":{"id":"0e575d99db10a18b","repo":"SonarSource/sonarqube","slug":"failed-to-create-temp-directory","errorCode":null,"errorMessage":"Failed to create temp directory","messagePattern":"Failed to create temp directory","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/DefaultTempFolder.java","lineNumber":62,"sourceCode":"  public DefaultTempFolder(File tempDir) {\n    this(tempDir, false);\n  }\n\n  public DefaultTempFolder(File tempDir, boolean deleteOnExit) {\n    this.tempDir = tempDir;\n    this.deleteOnExit = deleteOnExit;\n  }\n\n  @Override\n  public File newDir() {\n    return createTempDir(tempDir.toPath()).toFile();\n  }\n\n  private static Path createTempDir(Path baseDir) {\n    try {\n      return Files.createTempDirectory(baseDir, null);\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Failed to create temp directory\", e);\n    }\n  }\n\n  @Override\n  public File newDir(String name) {\n    File dir = new File(tempDir, name);\n    try {\n      FileUtils.forceMkdir(dir);\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Failed to create temp directory - \" + dir, e);\n    }\n    return dir;\n  }\n\n  @Override\n  public File newFile() {\n    return newFile(null, null);\n  }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/DefaultTempFolder.java#L44-L80","documentation":"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.","triggerScenarios":"Calling newDir()/newFile() construction path when the base temp directory cannot be created: parent missing, write permission denied, read-only filesystem, or disk full.","commonSituations":"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.","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"],"exampleFix":"// before\nPath base = Paths.get(\"/readonly/tmp\");\nDefaultTempFolder folder = new DefaultTempFolder(base, true);\n// after\nPath base = Paths.get(\"/var/tmp/sonar\");\nFiles.createDirectories(base);\nDefaultTempFolder folder = new DefaultTempFolder(base, true);","handlingStrategy":"try-catch","validationCode":"// ensure base dir is writable before constructing the temp folder\nPath base = Paths.get(tempPath);\nFiles.createDirectories(base);\nif (!Files.isWritable(base)) {\n  throw new IllegalStateException(\"temp base not writable: \" + base);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return newDir(name);\n} catch (IllegalStateException e) {\n  log.error(\"Temp dir creation failed: {}\", e.getCause());\n  throw new IOException(\"Check temp base permissions/disk space\", e);\n}","preventionTips":["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"],"tags":["filesystem","io","temp-directory"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}