Program: 31977
Project: 31977
Buggy source:
@Override public void shareKeysWithDevice(final IncomingRoomKeyRequest request){
  if ((null == request) || (null == request.mRequestBody)) {
    return;
  }
  final String userId=request.mUserId;
  final String deviceId=request.mDeviceId;
  final MXDeviceInfo deviceInfo=mSession.getCrypto().mCryptoStore.getUserDevice(deviceId,userId);
  final RoomKeyRequestBody body=request.mRequestBody;
  HashMap<String,ArrayList<MXDeviceInfo>> devicesByUser=new HashMap<>();
  devicesByUser.put(userId,new ArrayList<>(Arrays.asList(deviceInfo)));
  mSession.getCrypto().ensureOlmSessionsForDevices(devicesByUser,new ApiCallback<MXUsersDevicesMap<MXOlmSessionResult>>(){
    @Override public void onSuccess(    MXUsersDevicesMap<MXOlmSessionResult> map){
      MXOlmSessionResult olmSessionResult=map.getObject(deviceId,userId);
      if ((null == olmSessionResult) || (null == olmSessionResult.mSessionId)) {
        return;
      }
      Log.d(LOG_TAG,"String_Node_Str" + body.sender_key + "String_Node_Str"+ body.session_id+ "String_Node_Str"+ userId+ "String_Node_Str"+ deviceId);
      MXOlmInboundGroupSession2 inboundGroupSession=mSession.getCrypto().getOlmDevice().getInboundGroupSession(body.session_id,body.sender_key,body.room_id);
      Map<String,Object> payloadJson=new HashMap<>();
      payloadJson.put("String_Node_Str",Event.EVENT_TYPE_FORWARDED_ROOM_KEY);
      payloadJson.put("String_Node_Str",inboundGroupSession.exportKeys());
      Map<String,Object> encodedPayload=mSession.getCrypto().encryptMessage(payloadJson,Arrays.asList(deviceInfo));
      MXUsersDevicesMap<Map<String,Object>> sendToDeviceMap=new MXUsersDevicesMap<>();
      sendToDeviceMap.setObject(encodedPayload,userId,deviceId);
      Log.d(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId);
      mSession.getCryptoRestClient().sendToDevice(Event.EVENT_TYPE_MESSAGE_ENCRYPTED,sendToDeviceMap,new ApiCallback<Void>(){
        @Override public void onSuccess(        Void info){
          Log.d(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId);
        }
        @Override public void onNetworkError(        Exception e){
          Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
        }
        @Override public void onMatrixError(        MatrixError e){
          Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
        }
        @Override public void onUnexpectedError(        Exception e){
          Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
        }
      }
);
    }
    @Override public void onNetworkError(    Exception e){
      Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
    }
    @Override public void onMatrixError(    MatrixError e){
      Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
    }
    @Override public void onUnexpectedError(    Exception e){
      Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
    }
  }
);
}

Fixed version (ground truth):
@Override public void shareKeysWithDevice(final IncomingRoomKeyRequest request){
  if ((null == request) || (null == request.mRequestBody)) {
    return;
  }
  final String userId=request.mUserId;
  mSession.getCrypto().getDeviceList().downloadKeys(Arrays.asList(userId),false,new ApiCallback<MXUsersDevicesMap<MXDeviceInfo>>(){
    @Override public void onSuccess(    MXUsersDevicesMap<MXDeviceInfo> devicesMap){
      final String deviceId=request.mDeviceId;
      final MXDeviceInfo deviceInfo=mSession.getCrypto().mCryptoStore.getUserDevice(deviceId,userId);
      if (null != deviceInfo) {
        final RoomKeyRequestBody body=request.mRequestBody;
        HashMap<String,ArrayList<MXDeviceInfo>> devicesByUser=new HashMap<>();
        devicesByUser.put(userId,new ArrayList<>(Arrays.asList(deviceInfo)));
        mSession.getCrypto().ensureOlmSessionsForDevices(devicesByUser,new ApiCallback<MXUsersDevicesMap<MXOlmSessionResult>>(){
          @Override public void onSuccess(          MXUsersDevicesMap<MXOlmSessionResult> map){
            MXOlmSessionResult olmSessionResult=map.getObject(deviceId,userId);
            if ((null == olmSessionResult) || (null == olmSessionResult.mSessionId)) {
              return;
            }
            Log.d(LOG_TAG,"String_Node_Str" + body.sender_key + "String_Node_Str"+ body.session_id+ "String_Node_Str"+ userId+ "String_Node_Str"+ deviceId);
            MXOlmInboundGroupSession2 inboundGroupSession=mSession.getCrypto().getOlmDevice().getInboundGroupSession(body.session_id,body.sender_key,body.room_id);
            Map<String,Object> payloadJson=new HashMap<>();
            payloadJson.put("String_Node_Str",Event.EVENT_TYPE_FORWARDED_ROOM_KEY);
            payloadJson.put("String_Node_Str",inboundGroupSession.exportKeys());
            Map<String,Object> encodedPayload=mSession.getCrypto().encryptMessage(payloadJson,Arrays.asList(deviceInfo));
            MXUsersDevicesMap<Map<String,Object>> sendToDeviceMap=new MXUsersDevicesMap<>();
            sendToDeviceMap.setObject(encodedPayload,userId,deviceId);
            Log.d(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId);
            mSession.getCryptoRestClient().sendToDevice(Event.EVENT_TYPE_MESSAGE_ENCRYPTED,sendToDeviceMap,new ApiCallback<Void>(){
              @Override public void onSuccess(              Void info){
                Log.d(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId);
              }
              @Override public void onNetworkError(              Exception e){
                Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
              }
              @Override public void onMatrixError(              MatrixError e){
                Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
              }
              @Override public void onUnexpectedError(              Exception e){
                Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
              }
            }
);
          }
          @Override public void onNetworkError(          Exception e){
            Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
          }
          @Override public void onMatrixError(          MatrixError e){
            Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
          }
          @Override public void onUnexpectedError(          Exception e){
            Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str"+ e.getMessage());
          }
        }
);
      }
 else {
        Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ deviceId+ "String_Node_Str");
      }
    }
    @Override public void onNetworkError(    Exception e){
      Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ e.getMessage());
    }
    @Override public void onMatrixError(    MatrixError e){
      Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ e.getMessage());
    }
    @Override public void onUnexpectedError(    Exception e){
      Log.e(LOG_TAG,"String_Node_Str" + userId + "String_Node_Str"+ e.getMessage());
    }
  }
);
}