#vulnerable code 
                                @Override
    public void cancel() {
        lock.lock();
        try {
            if (this.finished) {
                return;
            }
            if (this.timer != null) {
                this.timer.cancel(true);
            }
            if (this.rpcCall != null) {
                this.rpcCall.cancel(true);
            }
            if (st.isOk()) {
                st.setError(RaftError.ECANCELED, RaftError.ECANCELED.name());
            }

            this.onFinished();
        } finally {
            lock.unlock();
        }

    } 
                            #location 9 
                            #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code
                                @Override
    public void cancel() {
        this.lock.lock();
        try {
            if (this.finished) {
                return;
            }
            if (this.timer != null) {
                this.timer.cancel(true);
            }
            if (this.rpcCall != null) {
                this.rpcCall.cancel(true);
            }
            if (this.st.isOk()) {
                this.st.setError(RaftError.ECANCELED, RaftError.ECANCELED.name());
            }

            this.onFinished();
        } finally {
            this.lock.unlock();
        }
    }