{"record":{"id":"c201a13e7fc52193","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-copy-jar-files-to-working-directory","errorCode":null,"errorMessage":"Failed to copy JAR files to working directory","messagePattern":"Failed to copy JAR files to 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":103,"sourceCode":"\t\t\t\tFiles.createDirectories(targetDir);\n\t\t\t}\n\n\t\t\t// Get all JAR files from lib directory\n\t\t\tPath libPath = Path.of(libUrl.toURI());\n\t\t\ttry (var stream = Files.walk(libPath)) {\n\t\t\t\tstream.filter(path -> path.toString().endsWith(\".jar\")).forEach(jarPath -> {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tPath targetPath = targetDir.resolve(jarPath.getFileName());\n\t\t\t\t\t\tFiles.copy(jarPath, targetPath, java.nio.file.StandardCopyOption.REPLACE_EXISTING);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (IOException e) {\n\t\t\t\t\t\tthrow new RuntimeException(\"Failed to copy JAR file: \" + jarPath, e);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new RuntimeException(\"Failed to copy JAR files to working directory\", e);\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);","sourceCodeStart":85,"sourceCodeEnd":121,"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#L85-L121","documentation":"The outer catch-all of copyResourceJarToWorkDir wraps any exception escaping the copy procedure — including the resource-not-found error, per-file copy failures, and directory creation errors — into this RuntimeException.","triggerScenarios":"Any failure inside copyResourceJarToWorkDir: missing 'lib' resource, unable to create targetDir, Files.walk failing on a closed/detached FileSystem (Spring Boot nested jars), or a wrapped per-JAR IOException bubbling up.","commonSituations":"Spring Boot nested-jar walking after the zip FileSystem is closed, missing resources/lib packaging, workDir creation denied, or the per-file RuntimeException being double-wrapped and obscuring the real cause.","solutions":["Unwrap the cause chain (getCause()) to find the root failure — often the nested 'Could not find lib directory' or a copy IOException.","Ensure the resources/lib directory is packaged on the classpath.","When loading from Spring Boot jars, open a FileSystem on the jar and keep it open for the duration of Files.walk.","Create the workDir beforehand with correct permissions."],"exampleFix":"// before\ncatch (Exception e) {\n    throw new RuntimeException(\"Failed to copy JAR files to working directory\", e);\n}\n// after\ncatch (Exception e) {\n    logger.error(\"copyResourceJarToWorkDir root cause\", e);\n    throw new RuntimeException(\"Failed to copy JAR files to working directory: \" + e.getMessage(), e);\n}","handlingStrategy":"try-catch","validationCode":"URL libUrl = FileUtils.class.getClassLoader().getResource(\"lib\");\nFiles.createDirectories(Path.of(workDir));","typeGuard":null,"tryCatchPattern":"try {\n    FileUtils.copyResourceJarToWorkDir(workDir);\n} catch (RuntimeException e) {\n    Throwable root = e;\n    while (root.getCause() != null) root = root.getCause();\n    logger.error(\"copyResourceJarToWorkDir failed, root cause: {}\", root.toString(), e);\n    throw e;\n}","preventionTips":["Always unwrap the cause chain — this message is a generic wrapper.","Validate resources/lib presence and workDir writability before the call.","Keep the jar FileSystem open while walking resources in Spring Boot.","Log the full stack trace, not just the wrapper message."],"tags":["file-copy","io","jar","classpath"],"backgroundTag":"file-write-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"}