```java
 public Result thenApplyWithContext(Function<Result, Result> fn) {
        this.thenApply(fn.compose(beforeContext).andThen(afterContext));
        // You may need to return a new Result instance representing the next async stage,
        // like thenApply will return a new CompletableFuture.
        return this;
    }
```

to

```java
```java
 public Result thenApplyWithContext(BiFunction<Throwable, Result> fn) {
        this.handle(fn);
        // You may need to return a new Result instance representing the next async stage,
        // like thenApply will return a new CompletableFuture.
        return this;
    }
```
```
@Override
    public void setAttachment(String key, String value) {
        getAppResponse().setAttachment(key, value);
    }
    public RpcContext getStoredContext() {
        return storedContext;
    }
    public RpcContext getStoredServerContext() {
        return storedServerContext;
    }
    public Invocation getInvocation() {
        return invocation;
    }
    /**
     * tmp context to use when the thread switch to Dubbo thread.
     */
    private RpcContext tmpContext;
    private RpcContext tmpServerContext;
    private Function<Result, Result> beforeContext = (appResponse) -> {
        tmpContext = RpcContext.getContext();
        tmpServerContext = RpcContext.getServerContext();
        RpcContext.restoreContext(storedContext);
        RpcContext.restoreServerContext(storedServerContext);
        return appResponse;
    };
    private Function<Result, Result> afterContext = (appResponse) -> {
        RpcContext.restoreContext(tmpContext);
        RpcContext.restoreServerContext(tmpServerContext);
        return appResponse;
    };