{"record":{"id":"d93ddd492884ba4f","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-copy-jar-file-jarpath","errorCode":null,"errorMessage":"Failed to copy JAR file: <jarPath>","messagePattern":"Failed to copy 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":142,"sourceCode":"\n\t/**\n\t * Copies all JAR files under the source directory to the target directory.\n\t * @param sourceDir The source directory containing JAR files.\n\t * @param targetDir The target directory where JAR files will be copied.\n\t * @throws IOException if I/O operations fail while scanning or copying files.\n\t */\n\tprivate static void copyJarFilesFromDir(Path sourceDir, Path targetDir) throws IOException {\n\t\tif (!Files.exists(sourceDir)) {\n\t\t\treturn;\n\t\t}\n\t\ttry (var stream = Files.walk(sourceDir)) {\n\t\t\tstream.filter(path -> path.toString().endsWith(\".jar\")).forEach(jarPath -> {\n\t\t\t\ttry {\n\t\t\t\t\tPath targetPath = targetDir.resolve(jarPath.getFileName().toString());\n\t\t\t\t\tFiles.copy(jarPath, targetPath, StandardCopyOption.REPLACE_EXISTING);\n\t\t\t\t}\n\t\t\t\tcatch (IOException e) {\n\t\t\t\t\tthrow new RuntimeException(\"Failed to copy JAR file: \" + jarPath, e);\n\t\t\t\t}\n\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}","sourceCodeStart":124,"sourceCodeEnd":160,"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#L124-L160","documentation":"Thrown inside FileUtils.copyJarFilesFromDir for each individual JAR file whose copy to the target directory fails with an IOException. The message includes the source path of the failing JAR; note it is thrown from a stream's forEach, aborting the whole copy operation on the first failure.","triggerScenarios":"Files.copy(jarPath, targetPath, REPLACE_EXISTING) throws IOException — typically because the source JAR disappeared during the walk, the target directory is not writable, or disk is full.","commonSituations":"Concurrent processes deleting/modifying JARs while walking; read-only or quota-exceeded target disk; antivirus/OS locking the target file on Windows.","solutions":["Check the wrapped IOException for the specific OS-level reason (access denied, no space, file in use).","Verify write permission and free space on the target directory.","Ensure no other process is locking or deleting the JARs while the copy runs.","Retry after cleaning the working directory via deleteResourceJarFromWorkDir."],"exampleFix":"// before\nFiles.copy(jarPath, targetPath, StandardCopyOption.REPLACE_EXISTING);\n// after: ensure target dir exists and is writable before the loop\nFiles.createDirectories(targetDir);\nif (!Files.isWritable(targetDir)) {\n    throw new IOException(\"Target dir not writable: \" + targetDir);\n}\nFiles.copy(jarPath, targetPath, StandardCopyOption.REPLACE_EXISTING);","handlingStrategy":"retry","validationCode":"if (!Files.isWritable(targetDir)) throw new IllegalStateException(\"Target dir not writable: \" + targetDir);\nif (targetDir.toFile().getUsableSpace() < 64L * 1024 * 1024) throw new IllegalStateException(\"Low disk space\");","typeGuard":null,"tryCatchPattern":"try {\n    FileUtils.copyResourceJarToWorkDir();\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof IOException io) {\n        logger.error(\"Copy failed for a JAR: {}\", io.getMessage(), io);\n        Files.createDirectories(targetDir); // then retry once\n        FileUtils.copyResourceJarToWorkDir();\n    }\n}","preventionTips":["Check disk space and write permissions on the target directory before copying.","Don't modify or delete JARs in the source/target directories while copying.","On Windows, exclude the directory from antivirus scanning."],"tags":["filesystem","io","file-copy"],"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-14T11:17:12.474Z"}