jeecgboot/JeecgBoot · error · IllegalArgumentException
命令不能为空
Error message
命令不能为空
What it means
Thrown by CommandExecUtil.execCommand(String, String[]) when the command string is null or empty. This is the string-overload entry point that splits the command by spaces and delegates to the array-based execCommand. It is a programmer-error guard — the method cannot execute anything without a binary name.
Source
Thrown at jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/CommandExecUtil.java:31
* @Date: 2024/4/8 10:11
*/
@Slf4j
public class CommandExecUtil {
/**
* 执行命令行
*
* @param command
* @param args
* @return
* @throws IOException
* @author chenrui
* @date 2024/4/9 10:59
*/
public static String execCommand(String command, String[] args) throws IOException {
if (null == command || command.isEmpty()) {
throw new IllegalArgumentException("命令不能为空");
}
return execCommand(command.split(" "), args);
}
/**
* 禁止在参数中出现的 Shell 元字符(适用于 Windows cmd 和 Unix shell)
*/
private static final Pattern SHELL_INJECTION_PATTERN =
Pattern.compile("[&|;<>`$!\\\\\\r\\n]");
/**
* 禁止文件名中出现的危险字符(防止通过文件名注入命令)
*/
private static final Pattern FILENAME_INJECTION_PATTERN =
Pattern.compile("[&|;<>`$!\"'\\r\\n]");
/**
* 校验单个命令参数,拒绝包含 Shell 注入字符的参数View on GitHub (pinned to 96fb33f5ec)
Solutions
- Verify the command string is non-null and non-empty before calling execCommand; add an upstream null/blank check.
- Check that the configuration or database field supplying the command is populated (e.g. MinerU / magic-pdf path in knowledge-base config).
- If the command comes from user input, validate and provide a clear error message at the API boundary rather than relying on this low-level guard.
Example fix
// before
String cmd = config.getCommand();
String result = CommandExecUtil.execCommand(cmd, args);
// after
String cmd = config.getCommand();
if (cmd == null || cmd.trim().isEmpty()) {
throw new JeecgBootException("命令未配置,请检查系统设置");
}
String result = CommandExecUtil.execCommand(cmd, args); Defensive patterns
Strategy: validation
Validate before calling
if (command == null || command.trim().isEmpty()) {
throw new JeecgBootException("命令未配置,请检查相关设置");
}
// safe to call
CommandExecUtil.execCommand(command, args); Try / catch
try {
CommandExecUtil.execCommand(command, args);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("命令不能为空")) {
log.error("Command not configured");
throw new JeecgBootException("执行命令未配置");
}
throw e;
} Prevention
- Always validate that command strings are non-null and non-blank before passing to execCommand.
- Use configuration validation at startup to fail fast if required external commands are not configured.
- Log the command array before execution to aid debugging.
When it happens
Trigger: Calling execCommand(null, args), execCommand("", args), or execCommand(" ", args) — the isEmpty() check passes for whitespace-only strings since it does not trim, but a literal empty string or null triggers it. Most commonly reached when a caller builds the command string from configuration or user input that was not validated upstream.
Common situations: Configuration property for the external binary (e.g. magic-pdf, conda) is missing from application.yml; a database column holding the command path is null; the caller passes a dynamically constructed string that evaluated to empty.
Related errors
- 命令参数包含非法字符,已拒绝执行:
- 文件路径包含非法字符,已拒绝处理:
- 编码长度必须能被固定位数整除
- Start year must be less than stop year
- 模板缺少参数:${item}
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/e2ecad8c818b082d.
Report an issue: GitHub.