{"record":{"id":"733be826de5482bf","repo":"GoogleContainerTools/jib","slug":"rootdir-is-not-a-directory","errorCode":null,"errorMessage":"rootDir + \" is not a directory\"","messagePattern":"rootDir \\+ \" is not a directory\"","errorType":"exception","errorClass":"NotDirectoryException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/filesystem/DirectoryWalker.java","lineNumber":42,"sourceCode":"import java.util.function.Predicate;\nimport java.util.stream.Stream;\n\n/** Recursively applies a function to each file in a directory. */\npublic class DirectoryWalker {\n\n  private final Path rootDir;\n\n  private Predicate<Path> pathFilter = path -> true;\n\n  /**\n   * Initialize with a root directory to walk.\n   *\n   * @param rootDir the root directory.\n   * @throws NotDirectoryException if the root directory is not a directory.\n   */\n  public DirectoryWalker(Path rootDir) throws NotDirectoryException {\n    if (!Files.isDirectory(rootDir)) {\n      throw new NotDirectoryException(rootDir + \" is not a directory\");\n    }\n    this.rootDir = rootDir;\n  }\n\n  /**\n   * Adds a filter to the walked paths.\n   *\n   * @param pathFilter the filter. {@code pathFilter} returns {@code true} if the path should be\n   *     accepted and {@code false} otherwise.\n   * @return this\n   */\n  public DirectoryWalker filter(Predicate<Path> pathFilter) {\n    this.pathFilter = this.pathFilter.and(pathFilter);\n    return this;\n  }\n\n  /**\n   * Filters away the {@code rootDir}.","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/filesystem/DirectoryWalker.java#L24-L60","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nnew DirectoryWalker(Path.of(\"config/app.yaml\")); // NotDirectoryException\n// after\nPath dir = Path.of(\"config\");\nif (!Files.isDirectory(dir)) {\n  throw new IllegalArgumentException(\"Expected a directory: \" + dir);\n}\nnew DirectoryWalker(dir);","handlingStrategy":"type-guard","validationCode":"// Java\nif (!Files.isDirectory(rootDir)) {\n  throw new IllegalArgumentException(\"Not a directory: \" + rootDir);\n}","typeGuard":"static boolean isDirectoryOrNull(Path p) {\n  return p != null && Files.isDirectory(p);\n}\n// use: if (isDirectoryOrNull(rootDir)) new DirectoryWalker(rootDir);","tryCatchPattern":"try {\n  new DirectoryWalker(rootDir);\n} catch (NotDirectoryException e) {\n  throw new BadConfigException(\"Layer source must be a directory: \" + e.getMessage(), e);\n}","preventionTips":["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"],"tags":["jib","filesystem","directory","validation"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}