{"record":{"id":"70788dca506bb688","repo":"SonarSource/sonarqube","slug":"failed-to-create-temp-directory-dir","errorCode":null,"errorMessage":"\"Failed to create temp directory - \" + dir","messagePattern":"\"Failed to create temp directory - \" \\+ dir","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/DefaultTempFolder.java","lineNumber":72,"sourceCode":"  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  }\n\n  @Override\n  public File newFile(@Nullable String prefix, @Nullable String suffix) {\n    return createTempFile(tempDir.toPath(), prefix, suffix).toFile();\n  }\n\n  private static Path createTempFile(Path baseDir, @Nullable String prefix, @Nullable String suffix) {\n    try {\n      return Files.createTempFile(baseDir, prefix, suffix);\n    } catch (IOException e) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/DefaultTempFolder.java#L54-L90","documentation":"DefaultTempFolder.newDir(name) creates a named subdirectory under the temp folder using FileUtils.forceMkdir. If an IOException occurs (permission denied, invalid name, parent missing, disk full) it is wrapped in this IllegalStateException including the target directory path. The library throws it because the caller expects a usable directory to be returned.","triggerScenarios":"Calling newDir(name) or newDir(String) when the subdirectory cannot be created: name invalid for the filesystem, temp base deleted while running, or insufficient write permissions.","commonSituations":"Illegal characters in the requested dir name on Windows; another process cleaning the temp folder concurrently; service accounts lacking write access to java.io.tmpdir; disk quota exceeded.","solutions":["Use a filesystem-safe name (no path separators or illegal characters) for newDir","Verify the DefaultTempFolder base directory still exists and is writable; recreate the folder if cleaned","Check process permissions and disk space/quota on the temp filesystem","Catch the IllegalStateException and fall back to Files.createTempDirectory on a known-writable path"],"exampleFix":"// before\nFile dir = tempFolder.newDir(\"sub/dir\"); // contains path separator\n// after\nFile dir = tempFolder.newDir(\"sub-dir\");","handlingStrategy":"validation","validationCode":"// validate dir name and base availability before newDir\nif (name == null || name.isEmpty() || name.contains(\"/\") || name.contains(\"\\\\\")) {\n  throw new IllegalArgumentException(\"invalid temp dir name: \" + name);\n}\nif (!Files.isDirectory(tempBase) || !Files.isWritable(tempBase)) {\n  throw new IllegalStateException(\"temp base missing or not writable: \" + tempBase);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return tempFolder.newDir(name);\n} catch (IllegalStateException e) {\n  log.error(\"newDir({}) failed: {}\", name, e.getCause());\n  throw e;\n}","preventionTips":["Use simple, filesystem-safe names without path separators","Verify the temp base survives external cleanup jobs","Check permissions and disk space before bulk temp operations","Sanitize user-supplied names before newDir"],"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"}