Program: 31968
Project: 31968
Buggy source:
/** 
 * Process any m.room_key_request events which were queued up during the current sync.
 */
private void processReceivedRoomKeyRequests(){
  List<IncomingRoomKeyRequest> receivedRoomKeyRequests=null;
synchronized (mReceivedRoomKeyRequests) {
    if (!mReceivedRoomKeyRequests.isEmpty()) {
      receivedRoomKeyRequests=new ArrayList(mReceivedRoomKeyRequests);
      mReceivedRoomKeyRequests.clear();
    }
  }
  if (null != receivedRoomKeyRequests) {
    for (    final IncomingRoomKeyRequest request : receivedRoomKeyRequests) {
      String userId=request.mUserId;
      String deviceId=request.mDeviceId;
      RoomKeyRequestBody body=request.mRequestBody;
      String roomId=body.room_id;
      String alg=body.algorithm;
      Log.d(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ roomId+ "String_Node_Str"+ body.session_id+ "String_Node_Str"+ request.mRequestId);
      if (!TextUtils.equals(mSession.getMyUserId(),userId)) {
        Log.e(LOG_TAG,"String_Node_Str");
        return;
      }
      final IMXDecrypting decryptor=getRoomDecryptor(roomId,alg);
      if (null == decryptor) {
        Log.e(LOG_TAG,"String_Node_Str" + alg + "String_Node_Str"+ roomId);
        continue;
      }
      if (!decryptor.hasKeysForKeyRequest(request)) {
        Log.e(LOG_TAG,"String_Node_Str" + body.session_id);
        mCryptoStore.deleteIncomingRoomKeyRequest(request);
        continue;
      }
      if (TextUtils.equals(deviceId,getMyDevice().deviceId) && TextUtils.equals(mSession.getMyUserId(),userId)) {
        Log.d(LOG_TAG,"String_Node_Str");
        mCryptoStore.deleteIncomingRoomKeyRequest(request);
        continue;
      }
      request.mShare=new Runnable(){
        @Override public void run(){
          getEncryptingThreadHandler().post(new Runnable(){
            @Override public void run(){
              decryptor.shareKeysWithDevice(request);
              mCryptoStore.deleteIncomingRoomKeyRequest(request);
            }
          }
);
        }
      }
;
      MXDeviceInfo device=mCryptoStore.getUserDevice(deviceId,userId);
      if (null != device) {
        if (device.isVerified()) {
          Log.d(LOG_TAG,"String_Node_Str");
          mCryptoStore.deleteIncomingRoomKeyRequest(request);
          request.mShare.run();
          continue;
        }
        if (device.isBlocked()) {
          Log.d(LOG_TAG,"String_Node_Str");
          mCryptoStore.deleteIncomingRoomKeyRequest(request);
          continue;
        }
      }
      mCryptoStore.storeIncomingRoomKeyRequest(request);
      onRoomKeyRequest(request);
    }
  }
  List<IncomingRoomKeyRequestCancellation> receivedRoomKeyRequestCancellations=null;
synchronized (mReceivedRoomKeyRequestCancellations) {
    if (!mReceivedRoomKeyRequestCancellations.isEmpty()) {
      receivedRoomKeyRequestCancellations=new ArrayList(mReceivedRoomKeyRequestCancellations);
      mReceivedRoomKeyRequestCancellations.clear();
    }
  }
  if (null != receivedRoomKeyRequestCancellations) {
    for (    IncomingRoomKeyRequestCancellation request : receivedRoomKeyRequestCancellations) {
      Log.d(LOG_TAG,"String_Node_Str" + request.mUserId + "String_Node_Str"+ request.mDeviceId+ "String_Node_Str"+ request.mRequestId);
      onRoomKeyRequestCancellation(request);
      mCryptoStore.deleteIncomingRoomKeyRequest(request);
    }
  }
}

Fixed version (ground truth):
/** 
 * Process any m.room_key_request events which were queued up during the current sync.
 */
private void processReceivedRoomKeyRequests(){
  List<IncomingRoomKeyRequest> receivedRoomKeyRequests=null;
synchronized (mReceivedRoomKeyRequests) {
    if (!mReceivedRoomKeyRequests.isEmpty()) {
      receivedRoomKeyRequests=new ArrayList(mReceivedRoomKeyRequests);
      mReceivedRoomKeyRequests.clear();
    }
  }
  if (null != receivedRoomKeyRequests) {
    for (    final IncomingRoomKeyRequest request : receivedRoomKeyRequests) {
      String userId=request.mUserId;
      String deviceId=request.mDeviceId;
      RoomKeyRequestBody body=request.mRequestBody;
      String roomId=body.room_id;
      String alg=body.algorithm;
      Log.d(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ roomId+ "String_Node_Str"+ body.session_id+ "String_Node_Str"+ request.mRequestId);
      if (!TextUtils.equals(mSession.getMyUserId(),userId)) {
        Log.e(LOG_TAG,"String_Node_Str");
        return;
      }
      final IMXDecrypting decryptor=getRoomDecryptor(roomId,alg);
      if (null == decryptor) {
        Log.e(LOG_TAG,"String_Node_Str" + alg + "String_Node_Str"+ roomId);
        continue;
      }
      if (!decryptor.hasKeysForKeyRequest(request)) {
        Log.e(LOG_TAG,"String_Node_Str" + body.session_id);
        mCryptoStore.deleteIncomingRoomKeyRequest(request);
        continue;
      }
      if (TextUtils.equals(deviceId,getMyDevice().deviceId) && TextUtils.equals(mSession.getMyUserId(),userId)) {
        Log.d(LOG_TAG,"String_Node_Str");
        mCryptoStore.deleteIncomingRoomKeyRequest(request);
        continue;
      }
      request.mShare=new Runnable(){
        @Override public void run(){
          getEncryptingThreadHandler().post(new Runnable(){
            @Override public void run(){
              decryptor.shareKeysWithDevice(request);
              mCryptoStore.deleteIncomingRoomKeyRequest(request);
            }
          }
);
        }
      }
;
      request.mIgnore=new Runnable(){
        @Override public void run(){
          getEncryptingThreadHandler().post(new Runnable(){
            @Override public void run(){
              mCryptoStore.deleteIncomingRoomKeyRequest(request);
            }
          }
);
        }
      }
;
      MXDeviceInfo device=mCryptoStore.getUserDevice(deviceId,userId);
      if (null != device) {
        if (device.isVerified()) {
          Log.d(LOG_TAG,"String_Node_Str");
          mCryptoStore.deleteIncomingRoomKeyRequest(request);
          request.mShare.run();
          continue;
        }
        if (device.isBlocked()) {
          Log.d(LOG_TAG,"String_Node_Str");
          mCryptoStore.deleteIncomingRoomKeyRequest(request);
          continue;
        }
      }
      mCryptoStore.storeIncomingRoomKeyRequest(request);
      onRoomKeyRequest(request);
    }
  }
  List<IncomingRoomKeyRequestCancellation> receivedRoomKeyRequestCancellations=null;
synchronized (mReceivedRoomKeyRequestCancellations) {
    if (!mReceivedRoomKeyRequestCancellations.isEmpty()) {
      receivedRoomKeyRequestCancellations=new ArrayList(mReceivedRoomKeyRequestCancellations);
      mReceivedRoomKeyRequestCancellations.clear();
    }
  }
  if (null != receivedRoomKeyRequestCancellations) {
    for (    IncomingRoomKeyRequestCancellation request : receivedRoomKeyRequestCancellations) {
      Log.d(LOG_TAG,"String_Node_Str" + request.mUserId + "String_Node_Str"+ request.mDeviceId+ "String_Node_Str"+ request.mRequestId);
      onRoomKeyRequestCancellation(request);
      mCryptoStore.deleteIncomingRoomKeyRequest(request);
    }
  }
}