apache/hadoop · error · IllegalArgumentException

Path ${files} cannot be empty.

Error message

Path ${files} cannot be empty.

What it means

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.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericOptionsParser.java:485

        }
      } else {
        // check if the file exists in this file system
        // we need to recreate this filesystem object to copy
        // these files to the file system ResourceManager is running
        // on.
        FileSystem fs = path.getFileSystem(conf);
        // existence check
        fs.getFileStatus(path);
        if (isWildcard) {
          expandWildcard(finalPaths, path, fs);
        } else {
          finalPaths.add(path.makeQualified(fs.getUri(),
              fs.getWorkingDirectory()).toString());
        }
      }
    }
    if (finalPaths.isEmpty()) {
      throw new IllegalArgumentException("Path " + files + " cannot be empty.");
    }
    return StringUtils.join(",", finalPaths);
  }

  private boolean matchesCurrentDirectory(String path) {
    return path.isEmpty() || path.equals(Path.CUR_DIR) ||
        path.equals(Path.CUR_DIR + File.separator);
  }

  private void expandWildcard(List<String> finalPaths, Path path, FileSystem fs)
      throws IOException {
    FileStatus status = fs.getFileStatus(path);
    if (!status.isDirectory()) {
      throw new FileNotFoundException(path + " is not a directory.");
    }
    // get all the jars in the directory
    List<Path> jars = FileUtil.getJarsInDirectory(path.toString(),
        fs.equals(FileSystem.getLocal(conf)));

View on GitHub (pinned to 2add963021)

Solutions

  1. Ensure the wildcard directory actually contains .jar files
  2. List the jar files explicitly instead of using '/*' when the directory is not a jar directory
  3. Drop the option entirely when nothing needs to be shipped

Example fix

# before: lib/ holds .class files, no jars
hadoop jar job.jar -libjars 'build/lib/*' Driver
# after: point at a real jar directory or name the jar
hadoop jar job.jar -libjars 'build/jars/*' Driver
Defensive patterns

Strategy: validation

Validate before calling

import java.nio.file.*;
boolean hasJars(String wildcardDir) {
  try (DirectoryStream<Path> s = Files.newDirectoryStream(Paths.get(wildcardDir), "*.jar")) {
    return s.iterator().hasNext();
  } catch (IOException e) {
    return false;
  }
}
// only pass -libjars 'dir/*' when hasJars("dir") is true

Prevention

When it happens

Trigger: A -libjars/-archives wildcard directory containing no .jar files (only classes, configs, or nothing); every entry filtered out during expansion so finalPaths stays empty.

Common situations: 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.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/2d1a9f9c6c2b4c1a. Report an issue: GitHub.