Program: 31991
Project: 31991
Buggy source:
/** 
 * Send an event content to the room. The event is updated with the data provided by the server The provided event contains the error description.
 * @param event    the message
 * @param callback the callback with the created event
 */
public void sendEvent(final Event event,final ApiCallback<Void> callback){
  if (!mIsReady || !selfJoined()) {
    event.mSentState=Event.SentState.WAITING_RETRY;
    try {
      callback.onNetworkError(null);
    }
 catch (    Exception e) {
      Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
    }
    return;
  }
  final ApiCallback<Event> localCB=new ApiCallback<Event>(){
    @Override public void onSuccess(    final Event serverResponseEvent){
      mStore.deleteEvent(event);
      event.mSentState=Event.SentState.SENT;
      event.eventId=serverResponseEvent.eventId;
      event.originServerTs=System.currentTimeMillis();
      if (!mStore.doesEventExist(serverResponseEvent.eventId,getRoomId())) {
        mStore.storeLiveRoomEvent(event);
      }
      sendReadReceipt();
      mStore.commit();
      mDataHandler.onSentEvent(event);
      try {
        callback.onSuccess(null);
      }
 catch (      Exception e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
      }
    }
    @Override public void onNetworkError(    Exception e){
      event.mSentState=Event.SentState.UNDELIVERABLE;
      event.unsentException=e;
      try {
        callback.onNetworkError(e);
      }
 catch (      Exception anException) {
        Log.e(LOG_TAG,"String_Node_Str" + anException.getMessage());
      }
    }
    @Override public void onMatrixError(    MatrixError e){
      event.mSentState=Event.SentState.UNDELIVERABLE;
      event.unsentMatrixError=e;
      if (TextUtils.equals(MatrixError.UNKNOWN_TOKEN,e.errcode)) {
        mDataHandler.onInvalidToken();
      }
 else {
        try {
          callback.onMatrixError(e);
        }
 catch (        Exception anException) {
          Log.e(LOG_TAG,"String_Node_Str" + anException.getMessage());
        }
      }
    }
    @Override public void onUnexpectedError(    Exception e){
      event.mSentState=Event.SentState.UNDELIVERABLE;
      event.unsentException=e;
      try {
        callback.onUnexpectedError(e);
      }
 catch (      Exception anException) {
        Log.e(LOG_TAG,"String_Node_Str" + anException.getMessage());
      }
    }
  }
;
  if (isEncrypted() && (null != mDataHandler.getCrypto())) {
    event.mSentState=Event.SentState.ENCRYPTING;
    mDataHandler.getCrypto().encryptEventContent(event.getContent().getAsJsonObject(),event.getType(),this,new ApiCallback<MXEncryptEventContentResult>(){
      @Override public void onSuccess(      MXEncryptEventContentResult encryptEventContentResult){
        event.type=encryptEventContentResult.mEventType;
        event.updateContent(encryptEventContentResult.mEventContent.getAsJsonObject());
        mDataHandler.getCrypto().decryptEvent(event,null);
        mDataHandler.onEventEncrypted(event);
        event.mSentState=Event.SentState.SENDING;
        mDataHandler.getDataRetriever().getRoomsRestClient().sendEventToRoom(event.originServerTs + "String_Node_Str",getRoomId(),encryptEventContentResult.mEventType,encryptEventContentResult.mEventContent.getAsJsonObject(),localCB);
      }
      @Override public void onNetworkError(      Exception e){
        event.mSentState=Event.SentState.UNDELIVERABLE;
        event.unsentException=e;
        if (null != callback) {
          callback.onNetworkError(e);
        }
      }
      @Override public void onMatrixError(      MatrixError e){
        if ((e instanceof MXCryptoError) && TextUtils.equals(((MXCryptoError)e).errcode,MXCryptoError.UNKNOWN_DEVICES_CODE)) {
          event.mSentState=Event.SentState.FAILED_UNKNOWN_DEVICES;
        }
 else {
          event.mSentState=Event.SentState.UNDELIVERABLE;
        }
        event.unsentMatrixError=e;
        if (null != callback) {
          callback.onMatrixError(e);
        }
      }
      @Override public void onUnexpectedError(      Exception e){
        event.mSentState=Event.SentState.UNDELIVERABLE;
        event.unsentException=e;
        if (null != callback) {
          callback.onUnexpectedError(e);
        }
      }
    }
);
  }
 else {
    event.mSentState=Event.SentState.SENDING;
    if (Event.EVENT_TYPE_MESSAGE.equals(event.getType())) {
      mDataHandler.getDataRetriever().getRoomsRestClient().sendMessage(event.originServerTs + "String_Node_Str",getRoomId(),JsonUtils.toMessage(event.getContent()),localCB);
    }
 else {
      mDataHandler.getDataRetriever().getRoomsRestClient().sendEventToRoom(event.originServerTs + "String_Node_Str",getRoomId(),event.getType(),event.getContent().getAsJsonObject(),localCB);
    }
  }
}

Fixed version (ground truth):
/** 
 * Send an event content to the room. The event is updated with the data provided by the server The provided event contains the error description.
 * @param event    the message
 * @param callback the callback with the created event
 */
public void sendEvent(final Event event,final ApiCallback<Void> callback){
  if (!mIsReady || !selfJoined()) {
    event.mSentState=Event.SentState.WAITING_RETRY;
    try {
      callback.onNetworkError(null);
    }
 catch (    Exception e) {
      Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
    }
    return;
  }
  final ApiCallback<Event> localCB=new ApiCallback<Event>(){
    @Override public void onSuccess(    final Event serverResponseEvent){
      mStore.deleteEvent(event);
      boolean isReadMarkerUpdated=TextUtils.equals(getReadMarkerEventId(),event.eventId);
      event.mSentState=Event.SentState.SENT;
      event.eventId=serverResponseEvent.eventId;
      event.originServerTs=System.currentTimeMillis();
      if (!mStore.doesEventExist(serverResponseEvent.eventId,getRoomId())) {
        mStore.storeLiveRoomEvent(event);
      }
      markAllAsRead(isReadMarkerUpdated,null);
      mStore.commit();
      mDataHandler.onSentEvent(event);
      try {
        callback.onSuccess(null);
      }
 catch (      Exception e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
      }
    }
    @Override public void onNetworkError(    Exception e){
      event.mSentState=Event.SentState.UNDELIVERABLE;
      event.unsentException=e;
      try {
        callback.onNetworkError(e);
      }
 catch (      Exception anException) {
        Log.e(LOG_TAG,"String_Node_Str" + anException.getMessage());
      }
    }
    @Override public void onMatrixError(    MatrixError e){
      event.mSentState=Event.SentState.UNDELIVERABLE;
      event.unsentMatrixError=e;
      if (TextUtils.equals(MatrixError.UNKNOWN_TOKEN,e.errcode)) {
        mDataHandler.onInvalidToken();
      }
 else {
        try {
          callback.onMatrixError(e);
        }
 catch (        Exception anException) {
          Log.e(LOG_TAG,"String_Node_Str" + anException.getMessage());
        }
      }
    }
    @Override public void onUnexpectedError(    Exception e){
      event.mSentState=Event.SentState.UNDELIVERABLE;
      event.unsentException=e;
      try {
        callback.onUnexpectedError(e);
      }
 catch (      Exception anException) {
        Log.e(LOG_TAG,"String_Node_Str" + anException.getMessage());
      }
    }
  }
;
  if (isEncrypted() && (null != mDataHandler.getCrypto())) {
    event.mSentState=Event.SentState.ENCRYPTING;
    mDataHandler.getCrypto().encryptEventContent(event.getContent().getAsJsonObject(),event.getType(),this,new ApiCallback<MXEncryptEventContentResult>(){
      @Override public void onSuccess(      MXEncryptEventContentResult encryptEventContentResult){
        event.type=encryptEventContentResult.mEventType;
        event.updateContent(encryptEventContentResult.mEventContent.getAsJsonObject());
        mDataHandler.getCrypto().decryptEvent(event,null);
        mDataHandler.onEventEncrypted(event);
        event.mSentState=Event.SentState.SENDING;
        mDataHandler.getDataRetriever().getRoomsRestClient().sendEventToRoom(event.originServerTs + "String_Node_Str",getRoomId(),encryptEventContentResult.mEventType,encryptEventContentResult.mEventContent.getAsJsonObject(),localCB);
      }
      @Override public void onNetworkError(      Exception e){
        event.mSentState=Event.SentState.UNDELIVERABLE;
        event.unsentException=e;
        if (null != callback) {
          callback.onNetworkError(e);
        }
      }
      @Override public void onMatrixError(      MatrixError e){
        if ((e instanceof MXCryptoError) && TextUtils.equals(((MXCryptoError)e).errcode,MXCryptoError.UNKNOWN_DEVICES_CODE)) {
          event.mSentState=Event.SentState.FAILED_UNKNOWN_DEVICES;
        }
 else {
          event.mSentState=Event.SentState.UNDELIVERABLE;
        }
        event.unsentMatrixError=e;
        if (null != callback) {
          callback.onMatrixError(e);
        }
      }
      @Override public void onUnexpectedError(      Exception e){
        event.mSentState=Event.SentState.UNDELIVERABLE;
        event.unsentException=e;
        if (null != callback) {
          callback.onUnexpectedError(e);
        }
      }
    }
);
  }
 else {
    event.mSentState=Event.SentState.SENDING;
    if (Event.EVENT_TYPE_MESSAGE.equals(event.getType())) {
      mDataHandler.getDataRetriever().getRoomsRestClient().sendMessage(event.originServerTs + "String_Node_Str",getRoomId(),JsonUtils.toMessage(event.getContent()),localCB);
    }
 else {
      mDataHandler.getDataRetriever().getRoomsRestClient().sendEventToRoom(event.originServerTs + "String_Node_Str",getRoomId(),event.getType(),event.getContent().getAsJsonObject(),localCB);
    }
  }
}