{"record":{"id":"f7f0506d4a49a7a3","repo":"SonarSource/sonarqube","slug":"can-not-delete","errorCode":null,"errorMessage":"Can not delete ","messagePattern":"Can not delete ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Files2.java","lineNumber":79,"sourceCode":"    }\n    if (fileOrDir.isDirectory()) {\n      FileUtils.deleteDirectory(fileOrDir);\n    } else {\n      Files.delete(fileOrDir.toPath());\n    }\n  }\n\n  /**\n   * Like {@link #deleteIfExistsOrThrowIOE(File)} but wraps {@link IOException}\n   * into {@link IllegalStateException}.\n   *\n   * @throws IllegalStateException in case deletion is unsuccessful\n   */\n  public void deleteIfExists(File fileOrDir) {\n    try {\n      deleteIfExistsOrThrowIOE(fileOrDir);\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Can not delete \" + fileOrDir, e);\n    }\n  }\n\n  /**\n   * Deletes a directory or a file if it exists, else does nothing. In the case\n   * of a directly, it is deleted recursively. Any exception is trapped and\n   * ignored.\n   *\n   * @param fileOrDir file or directory to delete. Can be {@code null}.\n   */\n  public void deleteQuietly(@Nullable File fileOrDir) {\n    FileUtils.deleteQuietly(fileOrDir);\n  }\n\n  /**\n   * Moves a file.\n   *\n   * <p>","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/util/Files2.java#L61-L97","documentation":"Files2.deleteIfExists(File) deletes a file or directory (recursively) if it exists, translating any IOException into an IllegalStateException with the message \"Can not delete \" plus the path. It is thrown when the underlying filesystem refuses or fails the deletion for any reason.","triggerScenarios":"deleteIfExistsOrThrowIOE throws IOException — target file/directory locked by another process, insufficient permissions, directory not empty due to undeletable children, or path on read-only/unavailable filesystem.","commonSituations":"CE temp files still held open by a lingering process on Windows; temp directory owned by a different user after running the CE as another account; read-only mount or full NFS stall; antivirus locking files.","solutions":["Check file/directory permissions and ownership on the target path and its parents","Find and stop processes holding the file open (lsof/handle.exe), especially on Windows","Verify the filesystem is writable and not a stale/read-only mount","Exclude the SonarQube temp/work directories from antivirus and backup scans"],"exampleFix":"// before\nfiles2.deleteIfExists(new File(\"/locked/dir\")); // IllegalStateException\n// after\nFile dir = new File(\"/locked/dir\");\nif (dir.exists() && dir.canWrite()) {\n  files2.deleteIfExists(dir);\n}","handlingStrategy":"validation","validationCode":"File target = new File(path);\nif (target.exists() && !target.canWrite()) {\n  throw new IllegalStateException(\"No permission to delete \" + target);\n}","typeGuard":null,"tryCatchPattern":"try {\n  files2.deleteIfExists(fileOrDir);\n} catch (IllegalStateException e) {\n  LOGGER.warn(\"Deletion failed for {} : {}\", fileOrDir, e.getCause());\n  // fall back to deleteOnExit or alert an operator\n}","preventionTips":["Run the CE service under a user that owns its work/temp directories","Exclude SonarQube temp dirs from antivirus/backup locks","Check for processes holding files open before cleanup (esp. Windows)","Ensure volumes are writable and not stale mounts"],"tags":["filesystem","delete","io","permissions"],"backgroundTag":"file-delete-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}