{"record":{"id":"c8d3858f9fc6bd33","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-delete-jar-files-from-working-directory","errorCode":null,"errorMessage":"Failed to delete JAR files from working directory","messagePattern":"Failed to delete JAR files from working directory","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/utils/FileUtils.java","lineNumber":128,"sourceCode":"\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":110,"sourceCodeEnd":133,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/utils/FileUtils.java#L110-L133","documentation":"FileUtils.deleteResourceJarFromWorkDir wraps any IOException encountered while removing extracted JAR files from the working directory in a RuntimeException with this message. It indicates that cleanup of dynamically copied resource JARs failed, typically due to file locks, permissions, or missing files.","triggerScenarios":"Calling deleteResourceJarFromWorkDir when the work-dir JAR files cannot be walked or deleted: IOExceptions from Files.walk/delete during cleanup (e.g. JAR still locked by a classloader, read-only directory, file already removed).","commonSituations":"On Windows where the JAR is held open by a URLClassLoader that was not closed; running under a user without write permission to the working directory; a concurrent process deleting the same files.","solutions":["Close any URLClassLoader or stream holding the JARs open before calling deleteResourceJarFromWorkDir (especially on Windows).","Verify the process user has write/delete permission on the working directory.","Check the wrapped IOException cause to identify the exact file that failed and delete it manually.","Make cleanup idempotent/retried at shutdown rather than mid-run."],"exampleFix":"// before\nclassLoader.close();\nfileUtils.deleteResourceJarFromWorkDir();\n// after\ntry (URLClassLoader cl = new URLClassLoader(urls)) {\n    // use cl\n}\ncl.close();\nfileUtils.deleteResourceJarFromWorkDir();","handlingStrategy":"try-catch","validationCode":"// before cleanup\ntry (var walk = Files.walk(workDir)) {\n  boolean allWritable = walk.allMatch(p -> Files.isWritable(p));\n  if (!allWritable) throw new IllegalStateException(\"work dir not writable\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  fileUtils.deleteResourceJarFromWorkDir();\n} catch (RuntimeException e) {\n  Throwable cause = e.getCause(); // IOException\n  log.warn(\"JAR cleanup failed: {}\", cause == null ? \"\" : cause.getMessage());\n}","preventionTips":["Close URLClassLoaders and streams before deleting JARs.","Run the app with a user owning the working directory.","Perform cleanup at controlled shutdown points only."],"tags":["io","file-deletion","runtime-exception"],"backgroundTag":"file-delete-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}