{"record":{"id":"25713c4d684ecc05","repo":"apache/hadoop","slug":"path-is-not-a-directory","errorCode":null,"errorMessage":"${path} is not a directory.","messagePattern":"(.+?) is not a directory\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java","lineNumber":499,"sourceCode":"        }\n      }\n    }\n    if (finalPaths.isEmpty()) {\n      throw new IllegalArgumentException(\"Path \" + files + \" cannot be empty.\");\n    }\n    return StringUtils.join(\",\", finalPaths);\n  }\n\n  private boolean matchesCurrentDirectory(String path) {\n    return path.isEmpty() || path.equals(Path.CUR_DIR) ||\n        path.equals(Path.CUR_DIR + File.separator);\n  }\n\n  private void expandWildcard(List<String> finalPaths, Path path, FileSystem fs)\n      throws IOException {\n    FileStatus status = fs.getFileStatus(path);\n    if (!status.isDirectory()) {\n      throw new FileNotFoundException(path + \" is not a directory.\");\n    }\n    // get all the jars in the directory\n    List<Path> jars = FileUtil.getJarsInDirectory(path.toString(),\n        fs.equals(FileSystem.getLocal(conf)));\n    if (jars.isEmpty()) {\n      LOG.warn(path + \" does not have jars in it. It will be ignored.\");\n    } else {\n      for (Path jar: jars) {\n        finalPaths.add(jar.makeQualified(fs.getUri(),\n            fs.getWorkingDirectory()).toString());\n      }\n    }\n  }\n\n  /**\n   * Windows powershell and cmd can parse key=value themselves, because\n   * /pkey=value is same as /pkey value under windows. However this is not\n   * compatible with how we get arbitrary key values in -Dkey=value format.","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java#L481-L517","documentation":"expandWildcard resolves the directory part of a wildcard entry such as `-libjars 'dir/*'`; if the FileStatus of that path is not a directory it throws FileNotFoundException('<path> is not a directory.'). The wildcard suffix was applied to something that is a regular file, so there is nothing to enumerate.","triggerScenarios":"-libjars '/path/lib/some.jar/*' — appending /* to a file path instead of a directory; a symlink in the wildcard prefix resolving to a file; scripts concatenating ${BASE}/* where BASE already includes a filename.","commonSituations":"Path variables that may hold either a file or a directory; copy-pasted commands mixing explicit jars and wildcard notation; symlinked lib paths changing target type.","solutions":["Apply the /* wildcard only to directories","Fix the script to concatenate the directory portion with /*","If the target is supposed to be a directory, replace the file occupying the path"],"exampleFix":"# before: BASE already includes the jar filename\nhadoop jar job.jar -libjars \"${BASE}/*\" Driver\n# after\nhadoop jar job.jar -libjars \"$(dirname \"$BASE\")/*\" Driver","handlingStrategy":"validation","validationCode":"import java.nio.file.*;\nString dir = wildcardPath.substring(0, wildcardPath.length() - 2); // strip '/*'\nif (!Files.isDirectory(Paths.get(dir))) {\n  throw new IllegalArgumentException(\"wildcard base is not a directory: \" + dir);\n}","typeGuard":null,"tryCatchPattern":"catch (FileNotFoundException e) {\n  // expandWildcard hit a non-directory: the /* was appended to a file path\n  log.error(\"apply /* only to directories: {}\", e.getMessage());\n}","preventionTips":["Apply '/*' only to paths you have verified are directories","Derive the directory portion explicitly (dirname) instead of concatenating blindly","Add argument sanity checks in scripts that mix explicit paths and wildcards"],"tags":["cli","generic-options-parser","libjars","wildcard","not-a-directory"],"backgroundTag":"not-a-directory","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}