{"record":{"id":"a2ee9e5352f3dd32","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-delete-jar-file-jarpath","errorCode":null,"errorMessage":"Failed to delete JAR file: <jarPath>","messagePattern":"Failed to delete JAR file: <jarPath>","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/utils/FileUtils.java","lineNumber":162,"sourceCode":"\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Deletes all JAR files from the specified working directory.\n\t * @param workDir The working directory from which the JAR files will be deleted.\n\t */\n\tpublic static void deleteResourceJarFromWorkDir(String workDir) {\n\t\ttry {\n\t\t\tPath workDirPath = Path.of(workDir);\n\t\t\tif (Files.exists(workDirPath)) {\n\t\t\t\ttry (var stream = Files.walk(workDirPath)) {\n\t\t\t\t\tstream.filter(path -> path.toString().endsWith(\".jar\")).forEach(jarPath -> {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tFiles.deleteIfExists(jarPath);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (IOException e) {\n\t\t\t\t\t\t\tthrow new RuntimeException(\"Failed to delete JAR file: \" + jarPath, e);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(\"Failed to delete JAR files from working directory\", e);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":144,"sourceCodeEnd":174,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/utils/FileUtils.java#L144-L174","documentation":"Thrown by FileUtils.deleteResourceJarFromWorkDir when deleting a specific JAR file from the working directory fails with an IOException. The message includes the path of the JAR that could not be deleted; commonly the file is locked by a running JVM or another process.","triggerScenarios":"Files.deleteIfExists(jarPath) fails during the walk — typically because the JAR is currently loaded/locked by the JVM, held open by another process, or the directory entry cannot be removed due to permissions.","commonSituations":"Trying to clean up working-dir JARs while the application still has classloaders pointing at them; Windows file locking; insufficient filesystem permissions in shared containers.","solutions":["Close classloaders or stop processes that loaded JARs from the working directory before cleanup.","Check the wrapped IOException cause (access denied vs file in use) for the OS-level reason.","Ensure the process has delete permission on the working directory.","On Windows, exclude JARs still in use, or schedule deletion for application shutdown."],"exampleFix":"// before: delete everything while JVM still holds locks\nstream.filter(p -> p.toString().endsWith(\".jar\")).forEach(p -> Files.deleteIfExists(p));\n// after: tolerate locked files and log instead of failing the whole walk\nstream.filter(p -> p.toString().endsWith(\".jar\")).forEach(p -> {\n    try {\n        Files.deleteIfExists(p);\n    } catch (IOException e) {\n        logger.warn(\"Could not delete locked JAR {}: {}\", p, e.getMessage());\n    }\n});","handlingStrategy":"try-catch","validationCode":"if (!Files.isDirectory(workDir)) return; // nothing to clean\ntry (var stream = Files.walk(workDir)) {\n    boolean anyJar = stream.anyMatch(p -> p.toString().endsWith(\".jar\"));\n}","typeGuard":null,"tryCatchPattern":"try {\n    FileUtils.deleteResourceJarFromWorkDir();\n} catch (RuntimeException e) {\n    logger.warn(\"JAR cleanup skipped: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());\n}","preventionTips":["Run cleanup at application shutdown, after classloaders have released the JARs.","Accept that locked JARs (JVM loaded) may not delete; treat cleanup as best-effort.","Verify delete permissions on the working directory in containers."],"tags":["filesystem","io","file-delete","file-lock"],"backgroundTag":"permission-denied","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}