{"record":{"id":"93e1a2ad44b325ab","repo":"SonarSource/sonarqube","slug":"failed-to-create-temp-file","errorCode":null,"errorMessage":"Failed to create temp file","messagePattern":"Failed to create temp file","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/DefaultTempFolder.java","lineNumber":91,"sourceCode":"    }\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) {\n      throw new IllegalStateException(\"Failed to create temp file\", e);\n    }\n  }\n\n  public void clean() {\n    try {\n      if (tempDir.exists()) {\n        Files.walkFileTree(tempDir.toPath(), DeleteRecursivelyFileVisitor.INSTANCE);\n      }\n    } catch (IOException e) {\n      LOG.error(\"Failed to delete temp folder\", e);\n    }\n  }\n\n  @Override\n  public void start() {\n    // nothing to do\n  }\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/DefaultTempFolder.java#L73-L109","documentation":"DefaultTempFolder.createTempFile creates a temporary file with Files.createTempFile inside the temp directory. An IOException (permissions, missing base dir, disk full, invalid prefix/suffix) is wrapped in this IllegalStateException. The library throws it because newFile() must return a usable, writable temp file.","triggerScenarios":"Calling newFile()/newFile(prefix, suffix) when the file cannot be created: temp base deleted at runtime, write permission denied, disk/quota exhausted, or prefix/suffix containing illegal path characters.","commonSituations":"Long prefix/suffix exceeding filesystem filename limits (e.g. 255 bytes); concurrent cleanup removing the temp dir; restricted service accounts; full disks in CI containers.","solutions":["Ensure the temp base directory exists and is writable (recreate DefaultTempFolder if it was cleaned)","Shorten the prefix/suffix and avoid illegal path characters","Check free disk space and quota on the temp filesystem","Inspect e.getCause() for permission details and fix OS-level access"],"exampleFix":"// before\nFile f = tempFolder.newFile(\"very-long-prefix-\" + uuid + \"-\", \".someext.tmp\");\n// after\nFile f = tempFolder.newFile(\"sonar-\", \".tmp\");","handlingStrategy":"try-catch","validationCode":"// ensure temp base exists and is writable before newFile\nif (!Files.isDirectory(tempBase) || !Files.isWritable(tempBase)) {\n  throw new IllegalStateException(\"temp base missing or not writable: \" + tempBase);\n}\nif ((prefix != null && prefix.length() > 100) || (suffix != null && suffix.length() > 50)) {\n  throw new IllegalArgumentException(\"prefix/suffix too long\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  return tempFolder.newFile(prefix, suffix);\n} catch (IllegalStateException e) {\n  log.error(\"Temp file creation failed: {}\", e.getCause());\n  throw new IOException(\"Unable to create temp file\", e);\n}","preventionTips":["Keep prefixes/suffixes short and free of path characters","Monitor free space and inodes on the temp filesystem","Recreate DefaultTempFolder after external cleanup","Run the service with write access to the temp directory"],"tags":["filesystem","io","temp-file"],"backgroundTag":"file-write-failed","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"}