{"record":{"id":"2d1a9f9c6c2b4c1a","repo":"apache/hadoop","slug":"path-files-cannot-be-empty","errorCode":null,"errorMessage":"Path ${files} cannot be empty.","messagePattern":"Path (.+?) cannot be empty\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java","lineNumber":485,"sourceCode":"        }\n      } else {\n        // check if the file exists in this file system\n        // we need to recreate this filesystem object to copy\n        // these files to the file system ResourceManager is running\n        // on.\n        FileSystem fs = path.getFileSystem(conf);\n        // existence check\n        fs.getFileStatus(path);\n        if (isWildcard) {\n          expandWildcard(finalPaths, path, fs);\n        } else {\n          finalPaths.add(path.makeQualified(fs.getUri(),\n              fs.getWorkingDirectory()).toString());\n        }\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)));","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java#L467-L503","documentation":"After every entry of a -files/-libjars/-archives value is resolved and qualified (and wildcards expanded), validateFiles requires at least one final path; an empty result throws IllegalArgumentException('Path <files> cannot be empty.'). The realistic route is wildcard expansion: expandWildcard only logs '<dir> does not have jars in it. It will be ignored.' for a jar-less directory and adds nothing, so `-libjars 'dir/*'` with zero .jar files in dir ends with an empty list and this error.","triggerScenarios":"A -libjars/-archives wildcard directory containing no .jar files (only classes, configs, or nothing); every entry filtered out during expansion so finalPaths stays empty.","commonSituations":"Pointing -libjars at a directory of class files or resources instead of jars; empty lib directories on freshly built projects; CI jobs referencing a lib dir before artifacts are copied in.","solutions":["Ensure the wildcard directory actually contains .jar files","List the jar files explicitly instead of using '/*' when the directory is not a jar directory","Drop the option entirely when nothing needs to be shipped"],"exampleFix":"# before: lib/ holds .class files, no jars\nhadoop jar job.jar -libjars 'build/lib/*' Driver\n# after: point at a real jar directory or name the jar\nhadoop jar job.jar -libjars 'build/jars/*' Driver","handlingStrategy":"validation","validationCode":"import java.nio.file.*;\nboolean hasJars(String wildcardDir) {\n  try (DirectoryStream<Path> s = Files.newDirectoryStream(Paths.get(wildcardDir), \"*.jar\")) {\n    return s.iterator().hasNext();\n  } catch (IOException e) {\n    return false;\n  }\n}\n// only pass -libjars 'dir/*' when hasJars(\"dir\") is true","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify wildcard directories actually contain .jar files before using '/*'","Prefer explicit jar lists in CI jobs over wildcards on build output dirs","Treat 'does not have jars in it' warnings as failures in job wrappers"],"tags":["cli","generic-options-parser","libjars","wildcard","validation"],"backgroundTag":"empty-path-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}