# blade create jvm return

## 介绍

指定类方法的返回值，仅支持基本类型、null 和 String 类型的返回值。

## 参数

以下是此场景特有参数，通用参数详见：\[blade create jvm]\(blade create jvm.md)

```
--effect-count string     影响的请求条数
--effect-percent string   影响的请求百分比
--value string     返回指定值，仅支持基本类型和字符串类型，如果想返回 null，可以设置为 --value null 。必选项
```

## 案例

指定com.example.controller.DubboController类，下面业务方法返回 "hello-chaosblade"

```
@RequestMapping(value = "hello")
@ResponseBody
public String hello(String name, int code) {
    if (name == null) {
        name = "friend";
    }
    StringBuilder result = null;
    try {
        result = new StringBuilder(sayHello(name));
    } catch (Exception e) {
        return e.getMessage() + "\n";
    }
    return result.toString() + "\n";
}
```

故障注入命令如下：

```
blade c jvm return --value hello-chaosblade --classname com.example.controller.DubboController --methodname hello --process tomcat
```

故障注入之前： ![](https://3224380698-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lj_V1osBR9CfezpYfj_%2Fuploads%2Fgit-blob-97d9e8da7a6fb7d6a3d38a30ed3972ba3ac7abaf%2F15758791534572.jpg?alt=media)

故障注入之后： ![](https://3224380698-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lj_V1osBR9CfezpYfj_%2Fuploads%2Fgit-blob-4eddde51cb96d1a27ba7bdceba1f0427904c1db5%2F15758792025977.jpg?alt=media)

停止实验：

```
blade d d31e24dea782a275
```

上述代码调用 sayHello 方法，我们对 sayHello 方法注入返回 null 故障，sayHello 方法如下：

```
private String sayHello(String name) throws BeansException {
    demoService = (DemoService)SpringContextUtil.getBean("demoService");
    StringBuilder result = new StringBuilder();
    result.append(demoService.sayHello(name));
    return result.toString();
}
```

执行以下命令：

```
blade c jvm return --value null --classname com.example.controller.DubboController --methodname sayHello --process tomcat
```

故障注入之后： ![](https://3224380698-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lj_V1osBR9CfezpYfj_%2Fuploads%2Fgit-blob-1cd4668665c35e60dd572847dd6ec3d8b371c1c4%2F15758793979757.jpg?alt=media)

## 常见问题
