{"record":{"id":"8e0615c1e28870b5","repo":"quarkusio/quarkus","slug":"failed-to-read-directory-dir","errorCode":null,"errorMessage":"Failed to read directory ${dir}","messagePattern":"Failed to read directory (.+?)","errorType":"exception","errorClass":"RegistryResolutionException","httpStatus":null,"severity":"error","filePath":"independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenRegistryCache.java","lineNumber":64,"sourceCode":"        log.debug(\"%s clearCache\", config.getId());\n        for (ArtifactCoords coords : artifacts) {\n            final Path dir;\n            try {\n                dir = resolver.findArtifactDirectory(new DefaultArtifact(coords.getGroupId(), coords.getArtifactId(),\n                        coords.getClassifier(), coords.getType(), coords.getVersion()));\n            } catch (BootstrapMavenException e) {\n                throw new RegistryResolutionException(\"Failed to resolve \" + coords + \" locally\", e);\n            }\n            if (Files.exists(dir)) {\n                try (Stream<Path> dirPaths = Files.list(dir)) {\n                    dirPaths.forEach(path -> {\n                        try {\n                            Files.delete(path);\n                        } catch (IOException e) {\n                        }\n                    });\n                } catch (IOException e) {\n                    throw new RegistryResolutionException(\"Failed to read directory \" + dir, e);\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":46,"sourceCodeEnd":70,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/tools/registry-client/src/main/java/io/quarkus/registry/client/maven/MavenRegistryCache.java#L46-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix permissions on the reported directory (chmod -R u+rwX or chown to the current user) and retry.","Check whether the path is on a read-only mount (mount | grep <path>) and remount read-write or use a writable repo location.","Run the cache clear as the same user that owns the Maven repository.","Delete the problematic directory manually (rm -rf) if listing cannot be repaired, then re-resolve artifacts.","Retry the operation — transient filesystem (NFS) errors may resolve on a second attempt."],"exampleFix":"// before: CI container failing to list root-owned cache\nrm -rf ~/.m2/repository && ./mvnw quarkus:registry-clear-cache\n// after: normalize ownership/permissions first\nsudo chown -R $(id -u):$(id -g) ~/.m2/repository && ./mvnw quarkus:registry-clear-cache","handlingStrategy":"try-catch","validationCode":"Path dir = Path.of(\n    System.getProperty(\"maven.repo.local\", System.getProperty(\"user.home\") + \"/.m2/repository\"),\n    coords.getGroupId().replace('.', '/'), coords.getArtifactId(), coords.getVersion());\n// pre-check readability of the directory before any cache-clear call\nif (Files.isDirectory(dir) && !Files.isReadable(dir)) {\n    throw new IllegalStateException(\"Directory not readable (fix permissions): \" + dir);\n}","typeGuard":"static boolean canListDirectory(Path dir) {\n    if (!Files.isDirectory(dir)) return false;\n    try (var s = Files.list(dir)) {\n        return s.findAny().isPresent() || true; // listable without IOException\n    } catch (IOException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    cache.clearCache(artifacts);\n} catch (RegistryResolutionException e) {\n    if (e.getMessage().startsWith(\"Failed to read directory\")) {\n        Path dir = Path.of(e.getMessage().replace(\"Failed to read directory \", \"\"));\n        // fall back to manual recursive delete if permissions allow\n        Files.walkFileTree(dir, new DeletingFileVisitor());\n    } else throw e;\n}","preventionTips":["Run builds and cache-clearing as the same user that owns ~/.m2/repository.","Avoid read-only mounts for the local Maven repository in containers/CI.","Normalize cache permissions after operations run as root (chown -R).","Check for NFS/shared-filesystem issues where listing may transiently fail.","Verify directories are actual directories, not stale symlinks or files."],"tags":["filesystem","permissions","maven","cache","io"],"backgroundTag":"filesystem-permission-denied","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}