{"record":{"id":"1f50613397d6eaca","repo":"elastic/elasticsearch","slug":"cannot-set-commandline-with-empty-list","errorCode":null,"errorMessage":"Cannot set commandline with empty list.","messagePattern":"Cannot set commandline with empty list\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java","lineNumber":288,"sourceCode":"            }\n        }\n    }\n\n    public void args(Object... args) {\n        args(List.of(args));\n    }\n\n    public void args(List<Object> args) {\n        getArgs().addAll(args);\n    }\n\n    public void commandLine(Object... args) {\n        commandLine(List.of(args));\n    }\n\n    public void commandLine(List<Object> args) {\n        if (args.isEmpty()) {\n            throw new IllegalArgumentException(\"Cannot set commandline with empty list.\");\n        }\n        getExecutable().set(args.get(0).toString());\n        getArgs().set(args.subList(1, args.size()));\n    }\n}\n","sourceCodeStart":270,"sourceCodeEnd":294,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java#L270-L294","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nloggedExec {\n  commandLine computedArgs // throws if computedArgs is empty\n}\n// after\nloggedExec {\n  if (!computedArgs.isEmpty()) {\n    commandLine computedArgs\n  }\n}","handlingStrategy":"validation","validationCode":"if (args.isEmpty()) {\n    throw new IllegalArgumentException(\"Refusing to set empty commandLine; provide at least the executable\");\n}\nloggedExec.commandLine(args);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["gradle","build-tools","exec","configuration-validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}