{"record":{"id":"6ebb283dc7133826","repo":"alibaba/arthas","slug":"vmtool-action","errorCode":null,"errorMessage":"vmtool: action 参数不能为空","messagePattern":"vmtool: action 参数不能为空","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/mcp/tool/function/jvm300/VMToolTool.java","lineNumber":48,"sourceCode":"\n            @ToolParam(description = \"返回实例限制数量 (-l)，getInstances 时使用，默认 10；<=0 表示不限制\", required = false)\n            Integer limit,\n\n            @ToolParam(description = \"结果对象展开层次 (-x)，默认 1\", required = false)\n            Integer expandLevel,\n\n            @ToolParam(description = \"OGNL 表达式，对 getInstances 返回的 instances 执行 (--express)\", required = false)\n            String express,\n\n            @ToolParam(description = \"线程 ID (-t)，interruptThread 时使用\", required = false)\n            Long threadId,\n\n            ToolContext toolContext\n    ) {\n        StringBuilder cmd = buildCommand(\"vmtool\");\n\n        if (action == null || action.trim().isEmpty()) {\n            throw new IllegalArgumentException(\"vmtool: action 参数不能为空\");\n        }\n        String normalizedAction = action.trim();\n        cmd.append(\" --action \").append(normalizedAction);\n\n        if (classLoaderHash != null && !classLoaderHash.trim().isEmpty()) {\n            addParameter(cmd, \"-c\", classLoaderHash);\n        } else if (classLoaderClass != null && !classLoaderClass.trim().isEmpty()) {\n            addParameter(cmd, \"--classLoaderClass\", classLoaderClass);\n        }\n\n        if (ACTION_GET_INSTANCES.equals(normalizedAction) || ACTION_REFERENCE_ANALYZE.equals(normalizedAction)) {\n            if (className == null || className.trim().isEmpty()) {\n                throw new IllegalArgumentException(\"vmtool \" + normalizedAction + \" 需要指定类名 (className)\");\n            }\n            addParameter(cmd, \"--className\", className);\n        }\n\n        if (ACTION_GET_INSTANCES.equals(normalizedAction)) {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/mcp/tool/function/jvm300/VMToolTool.java#L30-L66","documentation":"The vmtool MCP tool requires a non-null, non-blank action parameter to identify the operation type (getInstances, forceGc, interruptThread, referenceAnalyze). This is the first validation gate before any command construction begins.","triggerScenarios":"Calling the vmtool tool with action omitted, null, empty string, or whitespace-only value. The action parameter is declared required (no required=false annotation).","commonSituations":"MCP client omits the action field in the tool call; JSON serialization drops a null or empty field; field name typo (e.g., 'Action' instead of 'action').","solutions":["Provide a valid action value: getInstances, forceGc, interruptThread, or referenceAnalyze.","Verify the MCP client includes the action field with the correct key name.","Check that the action string is not just whitespace."],"exampleFix":"// before\nvmtool(action=null)\n// after\nvmtool(action=\"getInstances\", className=\"java.lang.String\")","handlingStrategy":"validation","validationCode":"// Before calling vmtool, validate action\nif (action == null || action.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"action is required for vmtool\");\n}\nSet<String> validActions = Set.of(\"getInstances\", \"forceGc\", \"interruptThread\", \"referenceAnalyze\");\nif (!validActions.contains(action.trim())) {\n    throw new IllegalArgumentException(\"Invalid vmtool action: \" + action);\n}","typeGuard":null,"tryCatchPattern":"try {\n    String result = vmtool(action, classLoaderHash, ...);\n} catch (IllegalArgumentException e) {\n    // action was null/empty/invalid — fix the caller to always send action\n}","preventionTips":["Always include the action field when calling the vmtool MCP tool.","Use a constant or enum for action values to avoid typos.","Validate required parameters client-side before invoking."],"tags":["vmtool","required-param","validation","arthas-mcp"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}