{"record":{"id":"e2ecad8c818b082d","repo":"jeecgboot/JeecgBoot","slug":"error-e2ecad","errorCode":null,"errorMessage":"命令不能为空","messagePattern":"命令不能为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/CommandExecUtil.java","lineNumber":31,"sourceCode":" * @Date: 2024/4/8 10:11\n */\n@Slf4j\npublic class CommandExecUtil {\n\n\n    /**\n     * 执行命令行\n     *\n     * @param command\n     * @param args\n     * @return\n     * @throws IOException\n     * @author chenrui\n     * @date 2024/4/9 10:59\n     */\n    public static String execCommand(String command, String[] args) throws IOException {\n        if (null == command || command.isEmpty()) {\n            throw new IllegalArgumentException(\"命令不能为空\");\n        }\n        return execCommand(command.split(\" \"), args);\n    }\n\n    /**\n     * 禁止在参数中出现的 Shell 元字符（适用于 Windows cmd 和 Unix shell）\n     */\n    private static final Pattern SHELL_INJECTION_PATTERN =\n            Pattern.compile(\"[&|;<>`$!\\\\\\\\\\\\r\\\\n]\");\n\n    /**\n     * 禁止文件名中出现的危险字符（防止通过文件名注入命令）\n     */\n    private static final Pattern FILENAME_INJECTION_PATTERN =\n            Pattern.compile(\"[&|;<>`$!\\\"'\\\\r\\\\n]\");\n\n    /**\n     * 校验单个命令参数，拒绝包含 Shell 注入字符的参数","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/CommandExecUtil.java#L13-L49","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nString cmd = config.getCommand();\nString result = CommandExecUtil.execCommand(cmd, args);\n\n// after\nString cmd = config.getCommand();\nif (cmd == null || cmd.trim().isEmpty()) {\n    throw new JeecgBootException(\"命令未配置，请检查系统设置\");\n}\nString result = CommandExecUtil.execCommand(cmd, args);","handlingStrategy":"validation","validationCode":"if (command == null || command.trim().isEmpty()) {\n    throw new JeecgBootException(\"命令未配置，请检查相关设置\");\n}\n// safe to call\nCommandExecUtil.execCommand(command, args);","typeGuard":null,"tryCatchPattern":"try {\n    CommandExecUtil.execCommand(command, args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"命令不能为空\")) {\n        log.error(\"Command not configured\");\n        throw new JeecgBootException(\"执行命令未配置\");\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["validation","command-execution","illegal-argument"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}