output: #fixed code
                                  void onRpcReturned(Status status, GetFileResponse response) {
          this.lock.lock();
          try {
              if (this.finished) {
                  return;
              }
              if (!status.isOk()) {
                  // Reset count to make next rpc retry the previous one
                  this.requestBuilder.setCount(0);
                  if (status.getCode() == RaftError.ECANCELED.getNumber()) {
                      if (this.st.isOk()) {
                          this.st.setError(status.getCode(), status.getErrorMsg());
                          this.onFinished();
                          return;
                      }
                  }
  
                  // Throttled reading failure does not increase _retry_times
                  if (status.getCode() != RaftError.EAGAIN.getNumber()
                      && ++this.retryTimes >= this.copyOptions.getMaxRetry()) {
                      if (this.st.isOk()) {
                          this.st.setError(status.getCode(), status.getErrorMsg());
                          this.onFinished();
                          return;
                      }
                  }
                  this.timer = this.timerManager.schedule(this::onTimer, this.copyOptions.getRetryIntervalMs(),
                          TimeUnit.MILLISECONDS);
                  return;
              }
              this.retryTimes = 0;
              Requires.requireNonNull(response, "response");
              // Reset count to |real_read_size| to make next rpc get the right offset
              if (response.hasReadSize() && response.getReadSize() != 0) {
                  this.requestBuilder.setCount(response.getReadSize());
              }
              if (this.outputStream != null) {
                  try {
                      response.getData().writeTo(this.outputStream);
                  } catch (final IOException e) {
                      LOG.error("Fail to write into file {}", this.destPath);
                      this.st.setError(RaftError.EIO, RaftError.EIO.name());
                      this.onFinished();
                      return;
                  }
              } else {
                  final byte[] data = response.getData().toByteArray();
                  this.destBuf.put(data);
              }
              if (response.getEof()) {
                  onFinished();
                  return;
              }
          } finally {
              this.lock.unlock();
          }
          sendNextRpc();
      }
input: #vulnerable code 
                                  void sendNextRpc() {
          this.timer = null;
          final long offset = requestBuilder.getOffset() + requestBuilder.getCount();
          final long maxCount = this.destBuf == null ? raftOptions.getMaxByteCountPerRpc() : Integer.MAX_VALUE;
          this.requestBuilder = requestBuilder.setOffset(offset).setCount(maxCount).setReadPartly(true);
          this.lock.lock();
          try {
              if (this.finished) {
                  return;
              }
              // throttle
              long newMaxCount = maxCount;
              if (this.snapshotThrottle != null) {
                  newMaxCount = snapshotThrottle.throttledByThroughput(maxCount);
                  if (newMaxCount == 0) {
                      // Reset count to make next rpc retry the previous one
                      this.requestBuilder.setCount(0);
                      this.timer = this.timerManager.schedule(this::onTimer, this.copyOptions.getRetryIntervalMs(),
                              TimeUnit.MILLISECONDS);
                      return;
                  }
              }
              this.requestBuilder.setCount(newMaxCount);
              LOG.debug("Send get file request {} to peer {}", this.requestBuilder.build(), this.endpoint);
              this.rpcCall = this.rpcService.getFile(endpoint, this.requestBuilder.build(),
                  this.copyOptions.getTimeoutMs(), done);
          } finally {
              lock.unlock();
          }
      } 
                              #location 5 
                              #vulnerability type THREAD_SAFETY_VIOLATION