apache/hadoop · error · IllegalArgumentException
Too many arguments.
Error message
Too many arguments.
What it means
CreateSnapshot.processOptions (SnapshotCommands.java:70) throws IllegalArgumentException('Too many arguments.') when more than two positional arguments remain after option parsing. createSnapshot accepts exactly one required directory plus at most one optional snapshot name; anything beyond that is rejected before the last argument is popped as the name.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java:70
public static final String USAGE = "<snapshotDir> [<snapshotName>]";
public static final String DESCRIPTION = "Create a snapshot on a directory";
private String snapshotName = null;
@Override
protected void processPath(PathData item) throws IOException {
if (!item.stat.isDirectory()) {
throw new PathIsNotDirectoryException(item.toString());
}
}
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
if (args.size() == 0) {
throw new IllegalArgumentException("<snapshotDir> is missing.");
}
if (args.size() > 2) {
throw new IllegalArgumentException("Too many arguments.");
}
if (args.size() == 2) {
snapshotName = args.removeLast();
}
}
@Override
protected void processArguments(LinkedList<PathData> items)
throws IOException {
super.processArguments(items);
if (numErrors != 0) { // check for error collecting paths
return;
}
assert(items.size() == 1);
PathData sroot = items.getFirst();
Path snapshotPath = sroot.fs.createSnapshot(sroot.path, snapshotName);
out.println("Created snapshot " + snapshotPath);
} View on GitHub (pinned to 2add963021)
Solutions
- Pass at most two arguments: directory and optional name: 'hadoop fs -createSnapshot /data mysnap'
- Quote variables in scripts ('"$SNAPDIR"') and validate they contain a single path
- Create snapshots per directory with separate invocations instead of batching directories in one command
Example fix
# before hadoop fs -createSnapshot /data /backup mysnap # createSnapshot: Too many arguments. # after hadoop fs -createSnapshot /data mysnap hadoop fs -createSnapshot /backup mysnap
Defensive patterns
Strategy: validation
Validate before calling
# exactly 1 or 2 args if (( $# < 1 || $# > 2 )); then echo "usage: createSnapshot <dir> [name]"; exit 2; fi hadoop fs -createSnapshot "$@"
Try / catch
catch (IllegalArgumentException e) when 'Too many arguments' -> drop extras; keep exactly <snapshotDir> [<snapshotName>] and re-run one command per directory
Prevention
- Quote variables that may contain spaces or multiple paths
- One createSnapshot call per directory
- Read the USAGE line (hadoop fs -createSnapshot) when scripting
When it happens
Trigger: 'hadoop fs -createSnapshot /dir name extra', 'hadoop fs -createSnapshot /dir /otherdir name' — three or more non-flag tokens. Typically caused by an unquoted variable expanding to multiple words (SNAPDIR='/data /data2').
Common situations: Shell scripts passing unquoted or multi-word variables; commands assembled by string concatenation that accidentally append another path; operators assuming multi-directory or name+comment arguments are supported like in other snapshot subcommands (renameSnapshot takes three).
Related errors
- <snapshotDir> is missing.
- Invalid read parameters: buf.length=%d, off=%d, len=%d
- Move destination must be different from source for %s.
- offset: %s is out of range [%s, %s]
- Invalid start or len parameter
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/f875101ae8a5df49.
Report an issue: GitHub.