GoogleContainerTools/jib · error · NotDirectoryException
rootDir + " is not a directory"
Error message
rootDir + " is not a directory"
What it means
The DirectoryWalker constructor validates that the given rootDir is actually a directory before walking it. If Files.isDirectory(rootDir) is false, it throws NotDirectoryException('<rootDir> is not a directory'). Jib requires a real directory to enumerate layered files.
Source
Thrown at jib-core/src/main/java/com/google/cloud/tools/jib/filesystem/DirectoryWalker.java:42
import java.util.function.Predicate;
import java.util.stream.Stream;
/** Recursively applies a function to each file in a directory. */
public class DirectoryWalker {
private final Path rootDir;
private Predicate<Path> pathFilter = path -> true;
/**
* Initialize with a root directory to walk.
*
* @param rootDir the root directory.
* @throws NotDirectoryException if the root directory is not a directory.
*/
public DirectoryWalker(Path rootDir) throws NotDirectoryException {
if (!Files.isDirectory(rootDir)) {
throw new NotDirectoryException(rootDir + " is not a directory");
}
this.rootDir = rootDir;
}
/**
* Adds a filter to the walked paths.
*
* @param pathFilter the filter. {@code pathFilter} returns {@code true} if the path should be
* accepted and {@code false} otherwise.
* @return this
*/
public DirectoryWalker filter(Predicate<Path> pathFilter) {
this.pathFilter = this.pathFilter.and(pathFilter);
return this;
}
/**
* Filters away the {@code rootDir}.View on GitHub (pinned to fb949e2676)
Solutions
- Check the path in the message: confirm it exists and is a directory (ls -ld <path>)
- Fix the configured path to point at the intended directory
- Create the directory if it is missing (Files.createDirectories(path))
- If you intended to include a single file, use a file-based layer/entry instead of DirectoryWalker
Example fix
// before
new DirectoryWalker(Path.of("config/app.yaml")); // NotDirectoryException
// after
Path dir = Path.of("config");
if (!Files.isDirectory(dir)) {
throw new IllegalArgumentException("Expected a directory: " + dir);
}
new DirectoryWalker(dir); Defensive patterns
Strategy: type-guard
Validate before calling
// Java
if (!Files.isDirectory(rootDir)) {
throw new IllegalArgumentException("Not a directory: " + rootDir);
} Type guard
static boolean isDirectoryOrNull(Path p) {
return p != null && Files.isDirectory(p);
}
// use: if (isDirectoryOrNull(rootDir)) new DirectoryWalker(rootDir); Try / catch
try {
new DirectoryWalker(rootDir);
} catch (NotDirectoryException e) {
throw new BadConfigException("Layer source must be a directory: " + e.getMessage(), e);
} Prevention
- Validate configured paths exist and are directories at config-load time
- Watch for files/symlinks where directories are expected
- Use Files.createDirectories for paths that should exist before the build
When it happens
Trigger: new DirectoryWalker(path) where path points to a regular file, a symlink target that is a file, or a nonexistent path (Files.isDirectory returns false for both).
Common situations: Configuring a jib layer's extra-files/directory to a file by mistake, typos in the configured path, or the path being deleted/replaced by a file before the build runs.
Related errors
- octalPermissions must be a 3-digit octal number (000-777)
- The class file (${jarEntry}) is of an invalid format.
- Reached end of class file (${jarEntry}) before being able to
- Invalid hash: ${hash}
- Invalid digest: ${digest}
AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06).
Data as JSON: /api/errors/733be826de5482bf.
Report an issue: GitHub.