skylot/jadx · warning · JadxRuntimeException

Failed to clear directory ${clearDir}

Error message

Failed to clear directory ${clearDir}

What it means

Thrown by clearDir(Path) when the underlying deleteDir(clearDir, true) throws. clearDir differs from deleteDir in that it keeps the root directory (keepRootDir=true, removing the root from the deletion list). The wrapped exception originates from Files.walkFileTree failing to traverse the directory, meaning the directory does not exist, is not readable, or has permission issues during traversal.

Source

Thrown at jadx-core/src/main/java/jadx/core/utils/files/FileUtils.java:237

					LOG.warn("Failed to delete directory {}", directory.toAbsolutePath(), e);
				}
			}
		} catch (Exception e) {
			throw new JadxRuntimeException("Failed to delete directory " + dir, e);
		}
	}

	public static void clearTempRootDir() {
		if (Files.isDirectory(tempRootDir)) {
			clearDir(tempRootDir);
		}
	}

	public static void clearDir(Path clearDir) {
		try {
			deleteDir(clearDir, true);
		} catch (Exception e) {
			throw new JadxRuntimeException("Failed to clear directory " + clearDir, e);
		}
	}

	/**
	 * Deprecated.
	 * Migrate to {@link IJadxFilesGetter} from jadx args to get temp dir
	 */
	@Deprecated
	public static Path createTempDir(String prefix) {
		try {
			Path dir = Files.createTempDirectory(tempRootDir, prefix);
			dir.toFile().deleteOnExit();
			return dir;
		} catch (Exception e) {
			throw new JadxRuntimeException("Failed to create temp directory with suffix: " + prefix, e);
		}
	}

View on GitHub (pinned to e738a26571)

Solutions

  1. Guard with Files.isDirectory(clearDir) before calling.
  2. Use clearTempRootDir() which already has an isDirectory guard, if you are clearing the default temp root.
  3. Close all open file handles before clearing on Windows.
  4. Check the cause to distinguish 'not found' from 'permission denied'.

Example fix

// before
FileUtils.clearDir(workDir);

// after
if (Files.isDirectory(workDir)) {
    FileUtils.clearDir(workDir);
}
Defensive patterns

Strategy: validation

Validate before calling

public static boolean isClearableDir(Path dir) {
    return Files.isDirectory(dir) && Files.isReadable(dir);
}

Try / catch

try {
    FileUtils.clearDir(dir);
} catch (JadxRuntimeException e) {
    if (e.getCause() instanceof NoSuchFileException) return;
    LOG.warn("could not clear dir {}: {}", dir, e.getCause().getMessage());
}

Prevention

When it happens

Trigger: Calling clearDir on a path that does not exist or is not a directory. Permission denied when trying to read or delete contents. Filesystem errors during walkFileTree traversal of the directory tree.

Common situations: Calling clearDir on a temp directory that was already cleaned up by clearTempRootDir or an external process. A file handle still open inside the directory on Windows preventing deletion. Permission mismatch where files were created by a different OS user. Network share disconnection during traversal.

Related errors


AI-assisted analysis of skylot/jadx@e738a26571 (2026-08-14). Data as JSON: /api/errors/58d95f727954d70d. Report an issue: GitHub.