quarkusio/quarkus · error · RegistryResolutionException

Failed to read directory ${dir}

Error message

Failed to read directory ${dir}

What it means

Thrown by MavenRegistryCache.clearCache when Files.list(dir) fails with an IOException while trying to enumerate the contents of an artifact's local-repository directory before deleting each entry. The directory exists but cannot be read/listed (e.g. permission denied, or it stopped being a readable directory). The IOException is preserved as the cause.

Source

Thrown at independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenRegistryCache.java:64

        log.debug("%s clearCache", config.getId());
        for (ArtifactCoords coords : artifacts) {
            final Path dir;
            try {
                dir = resolver.findArtifactDirectory(new DefaultArtifact(coords.getGroupId(), coords.getArtifactId(),
                        coords.getClassifier(), coords.getType(), coords.getVersion()));
            } catch (BootstrapMavenException e) {
                throw new RegistryResolutionException("Failed to resolve " + coords + " locally", e);
            }
            if (Files.exists(dir)) {
                try (Stream<Path> dirPaths = Files.list(dir)) {
                    dirPaths.forEach(path -> {
                        try {
                            Files.delete(path);
                        } catch (IOException e) {
                        }
                    });
                } catch (IOException e) {
                    throw new RegistryResolutionException("Failed to read directory " + dir, e);
                }
            }
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Fix permissions on the reported directory (chmod -R u+rwX or chown to the current user) and retry.
  2. Check whether the path is on a read-only mount (mount | grep <path>) and remount read-write or use a writable repo location.
  3. Run the cache clear as the same user that owns the Maven repository.
  4. Delete the problematic directory manually (rm -rf) if listing cannot be repaired, then re-resolve artifacts.
  5. Retry the operation — transient filesystem (NFS) errors may resolve on a second attempt.

Example fix

// before: CI container failing to list root-owned cache
rm -rf ~/.m2/repository && ./mvnw quarkus:registry-clear-cache
// after: normalize ownership/permissions first
sudo chown -R $(id -u):$(id -g) ~/.m2/repository && ./mvnw quarkus:registry-clear-cache
Defensive patterns

Strategy: try-catch

Validate before calling

Path dir = Path.of(
    System.getProperty("maven.repo.local", System.getProperty("user.home") + "/.m2/repository"),
    coords.getGroupId().replace('.', '/'), coords.getArtifactId(), coords.getVersion());
// pre-check readability of the directory before any cache-clear call
if (Files.isDirectory(dir) && !Files.isReadable(dir)) {
    throw new IllegalStateException("Directory not readable (fix permissions): " + dir);
}

Type guard

static boolean canListDirectory(Path dir) {
    if (!Files.isDirectory(dir)) return false;
    try (var s = Files.list(dir)) {
        return s.findAny().isPresent() || true; // listable without IOException
    } catch (IOException e) {
        return false;
    }
}

Try / catch

try {
    cache.clearCache(artifacts);
} catch (RegistryResolutionException e) {
    if (e.getMessage().startsWith("Failed to read directory")) {
        Path dir = Path.of(e.getMessage().replace("Failed to read directory ", ""));
        // fall back to manual recursive delete if permissions allow
        Files.walkFileTree(dir, new DeletingFileVisitor());
    } else throw e;
}

Prevention

When it happens

Trigger: Calling clearCache where an artifact directory exists in the local repository but Files.list throws IOException — typically permission-denied on the directory, or the path was replaced by a non-directory between the Files.exists check and the listing.

Common situations: CI containers running as a different user than whoever created the Maven cache (root vs ci-user) leaving unreadable directories; read-only mounted cache volumes; NFS/permission issues in shared ~/.m2 caches; race conditions where another process deletes or replaces the directory mid-run.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/8e0615c1e28870b5. Report an issue: GitHub.