elastic/elasticsearch · error · IllegalArgumentException
Cannot set commandline with empty list.
Error message
Cannot set commandline with empty list.
What it means
LoggedExec.commandLine(List) throws IllegalArgumentException when the provided list is empty. The first element is interpreted as the executable path and the remainder as args; an empty list means no executable was specified, which would leave getExecutable() unset and cause a confusing downstream failure. The check fails fast at configuration time with a clear message.
Source
Thrown at build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java:288
}
}
}
public void args(Object... args) {
args(List.of(args));
}
public void args(List<Object> args) {
getArgs().addAll(args);
}
public void commandLine(Object... args) {
commandLine(List.of(args));
}
public void commandLine(List<Object> args) {
if (args.isEmpty()) {
throw new IllegalArgumentException("Cannot set commandline with empty list.");
}
getExecutable().set(args.get(0).toString());
getArgs().set(args.subList(1, args.size()));
}
}
View on GitHub (pinned to db6a809a66)
Solutions
- Guard the call: only invoke commandLine(list) when list is non-empty, and skip or skip the task if the command is missing.
- Validate the list at configuration time and fail with a more contextual message before reaching commandLine().
- Ensure the varargs form commandLine(Object...) is never called with zero arguments.
Example fix
// before
loggedExec {
commandLine computedArgs // throws if computedArgs is empty
}
// after
loggedExec {
if (!computedArgs.isEmpty()) {
commandLine computedArgs
}
} Defensive patterns
Strategy: validation
Validate before calling
if (args.isEmpty()) {
throw new IllegalArgumentException("Refusing to set empty commandLine; provide at least the executable");
}
loggedExec.commandLine(args); Prevention
- Validate dynamically-built command lists are non-empty before calling commandLine.
- Never call commandLine() with zero varargs arguments.
- Skip or disable the LoggedExec task entirely if the command is conditionally absent.
When it happens
Trigger: Calling commandLine() with no arguments (varargs form forwards an empty List.of()), or commandLine(emptyList) / commandLine(List.of()) directly. Common when the command is built dynamically from a collection that happens to be empty.
Common situations: Building the command list from filtered/conditional collections that may be empty; refactoring a commandLine(a, b, c) call to commandLine(list) where list is computed; passing a config-provided list that wasn't validated.
Related errors
- Capturing output is not supported when indentingConsoleOutpu
- Capturing output was not enabled. Use ${name}.getCapturedOut
- platform cannot be set on elasticsearch distribution [${name
- bundledJdk cannot be set on elasticsearch distribution [${na
- Failed to read exec output
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/1f50613397d6eaca.
Report an issue: GitHub.