quarkusio/quarkus · error · IllegalStateException

Failed to locate directory <dir>

Error message

Failed to locate directory <dir>

What it means

DirectoryResourceLoader's constructor validates that the given Path is an existing directory and throws IllegalStateException immediately otherwise. The loader is being constructed against a path that doesn't exist or is a regular file.

Source

Thrown at independent-projects/tools/devtools-common/src/main/java/io/quarkus/platform/descriptor/loader/json/DirectoryResourceLoader.java:13

package io.quarkus.platform.descriptor.loader.json;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class DirectoryResourceLoader implements ResourceLoader {

    private final Path dir;

    public DirectoryResourceLoader(Path dir) {
        if (!Files.isDirectory(dir)) {
            throw new IllegalStateException("Failed to locate directory " + dir);
        }
        this.dir = dir;
    }

    @Override
    public <T> T loadResourceAsPath(String name, ResourcePathConsumer<T> consumer) throws IOException {
        Path path = dir.resolve(name);
        if (!Files.exists(path)) {
            throw new IOException("Failed to locate " + name + " dir on the classpath");
        }
        return consumer.consume(path);
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Verify the path exists and is a directory (Files.isDirectory) before constructing
  2. Fix the configured path/working directory
  3. Create the directory if it is supposed to exist
  4. If the source may be a jar/zip instead, use ResourceLoaders.resolveFileResourceLoader which picks the right loader

Example fix

// before
new DirectoryResourceLoader(Path.of("maybe-missing"));
// after
Path p = Path.of("maybe-missing");
if (Files.isDirectory(p)) {
    new DirectoryResourceLoader(p);
} else {
    ResourceLoaders.resolveFileResourceLoader(p.toFile());
}
Defensive patterns

Strategy: validation

Validate before calling

Path dir = Path.of(configuredPath);
if (!Files.isDirectory(dir)) {
    throw new IllegalArgumentException("Not a directory: " + dir.toAbsolutePath());
}

Type guard

boolean isUsableResourceDir(Path p) {
    return p != null && Files.isDirectory(p);
}

Try / catch

try {
    loader = new DirectoryResourceLoader(dir);
} catch (IllegalStateException e) {
    if (e.getMessage().startsWith("Failed to locate directory")) {
        throw new ConfigurationException("Configured descriptor directory does not exist: " + dir, e);
    }
    throw e;
}

Prevention

When it happens

Trigger: new DirectoryResourceLoader(dir) where dir is missing, deleted, points to a file, or has a typo (unresolved symlink, wrong working directory).

Common situations: Local platform descriptor checkout path misconfigured; running from a different working directory than expected; directory removed by a clean build before tooling runs.

Related errors


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