alibaba/spring-ai-alibaba · error · RuntimeException

Failed to delete JAR files from working directory

Error message

Failed to delete JAR files from working directory

What it means

Outer wrapper thrown by FileUtils.deleteResourceJarFromWorkDir when the Files.walk over the working directory itself fails with an IOException. It means the cleanup could not even enumerate the JAR files, e.g. because the directory does not exist or is unreadable.

Source

Thrown at spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/utils/FileUtils.java:169

	 */
	public static void deleteResourceJarFromWorkDir(String workDir) {
		try {
			Path workDirPath = Path.of(workDir);
			if (Files.exists(workDirPath)) {
				try (var stream = Files.walk(workDirPath)) {
					stream.filter(path -> path.toString().endsWith(".jar")).forEach(jarPath -> {
						try {
							Files.deleteIfExists(jarPath);
						}
						catch (IOException e) {
							throw new RuntimeException("Failed to delete JAR file: " + jarPath, e);
						}
					});
				}
			}
		}
		catch (IOException e) {
			throw new RuntimeException("Failed to delete JAR files from working directory", e);
		}
	}

}

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Check that the working directory exists and is readable before calling cleanup.
  2. Inspect the wrapped IOException cause for the exact filesystem error.
  3. Guard the call with a directory-existence check or treat 'no directory' as a no-op.
  4. Fix permissions on the working directory or point cleanup at the correct path.

Example fix

// before: cleanup assumes dir exists
FileUtils.deleteResourceJarFromWorkDir();
// after: no-op when the dir is absent
Path workDir = Path.of(workDirPath);
if (Files.isDirectory(workDir)) {
    FileUtils.deleteResourceJarFromWorkDir();
}
Defensive patterns

Strategy: fallback

Validate before calling

Path workDir = Path.of(workDirPath);
if (!Files.isDirectory(workDir)) {
    logger.info("Work dir {} absent; skipping cleanup", workDir);
    return;
}

Try / catch

try {
    FileUtils.deleteResourceJarFromWorkDir();
} catch (RuntimeException e) {
    logger.warn("Cleanup skipped (walk failed): {}", e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
}

Prevention

When it happens

Trigger: Files.walk(workDirPath) throws IOException — the working directory was removed concurrently, the path is not a directory, or the filesystem is inaccessible/unreadable.

Common situations: Calling cleanup before copyResourceJarToWorkDir ever created the directory; container volumes unmounted mid-run; permission changes on shared working directories.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/8fbaad4f8fec8af0. Report an issue: GitHub.