Program: 32186
Project: 32186
Buggy source:
/** 
 * Use the API sync V1 to get the events
 */
private void runV1(){
  if (null != mCurrentToken) {
    Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  }
 else {
    Log.d(LOG_TAG,"String_Node_Str");
  }
  mPaused=false;
  if (null != mCurrentToken) {
    mInitialSyncDone=true;
    mListener.onInitialSyncComplete(null);
synchronized (mEventsRestClientV1) {
      mIsGettingPresences=true;
    }
    Log.d(LOG_TAG,"String_Node_Str");
    mEventsRestClientV1.initialSyncWithLimit(new SimpleApiCallback<InitialSyncResponse>(mFailureCallback){
      @Override public void onSuccess(      InitialSyncResponse initialSync){
        Log.d(LOG_TAG,"String_Node_Str");
        mListener.onMembersPresencesSyncComplete(initialSync.presence);
        Log.d(LOG_TAG,"String_Node_Str");
synchronized (mEventsRestClientV1) {
          mIsGettingPresences=false;
        }
      }
      @Override public void onNetworkError(      Exception e){
synchronized (mEventsRestClientV1) {
          mIsGettingPresences=false;
        }
      }
      @Override public void onMatrixError(      MatrixError e){
synchronized (mEventsRestClientV1) {
          mIsGettingPresences=false;
        }
      }
      @Override public void onUnexpectedError(      Exception e){
synchronized (mEventsRestClientV1) {
          mIsGettingPresences=false;
        }
      }
    }
,0);
  }
  while (!mInitialSyncDone) {
    final CountDownLatch latch=new CountDownLatch(1);
    mEventsRestClientV1.initialSyncWithLimit(new SimpleApiCallback<InitialSyncResponse>(mFailureCallback){
      @Override public void onSuccess(      InitialSyncResponse initialSync){
        Log.i(LOG_TAG,"String_Node_Str");
        mListener.onInitialSyncComplete(initialSync);
        mCurrentToken=initialSync.end;
        mInitialSyncDone=true;
        latch.countDown();
      }
      private void sleepAndUnblock(){
        new Handler().postDelayed(new Runnable(){
          public void run(){
            latch.countDown();
          }
        }
,RETRY_WAIT_TIME_MS);
      }
      @Override public void onNetworkError(      Exception e){
        if (null != mCurrentToken) {
          onSuccess(null);
        }
 else {
          Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
          super.onNetworkError(e);
          sleepAndUnblock();
        }
      }
      @Override public void onMatrixError(      MatrixError e){
        Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
        super.onMatrixError(e);
        sleepAndUnblock();
      }
      @Override public void onUnexpectedError(      Exception e){
        super.onUnexpectedError(e);
        Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
        sleepAndUnblock();
      }
    }
,10);
    try {
      latch.await();
    }
 catch (    InterruptedException e) {
      Log.e(LOG_TAG,"String_Node_Str");
    }
  }
  Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  if (null != mNetworkConnectivityReceiver) {
    mNetworkConnectivityReceiver.addEventListener(mNetworkListener);
    mbIsConnected=mNetworkConnectivityReceiver.isConnected();
    mPaused=!mbIsConnected;
  }
  while (!mKilling) {
    if (mPaused || mIsNetworkSuspended) {
      if (mIsNetworkSuspended) {
        Log.d(LOG_TAG,"String_Node_Str");
      }
 else {
        Log.d(LOG_TAG,"String_Node_Str");
      }
      try {
synchronized (this) {
          wait();
        }
        Log.d(LOG_TAG,"String_Node_Str");
      }
 catch (      InterruptedException e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
      }
    }
    if (!mKilling) {
      try {
        Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
        TokensChunkResponse<Event> eventsResponse=mEventsRestClientV1.events(mCurrentToken,mEventRequestTimeout);
        if (null != eventsResponse.chunk) {
          Log.d(LOG_TAG,"String_Node_Str" + eventsResponse.chunk.size() + "String_Node_Str");
        }
 else {
          Log.d(LOG_TAG,"String_Node_Str");
        }
        if (!mKilling) {
          if ((null != eventsResponse.chunk) && (eventsResponse.chunk.size() > 0)) {
            eventsResponse.chunk.get(0).setIntenalPaginationToken(eventsResponse.start);
            eventsResponse.chunk.get(eventsResponse.chunk.size() - 1).setIntenalPaginationToken(eventsResponse.end);
          }
          Boolean isGettingsPresence;
synchronized (mEventsRestClientV1) {
            isGettingsPresence=mIsGettingPresences;
          }
          if (isGettingsPresence) {
            ArrayList<Event> events=new ArrayList<Event>();
            for (            Event event : eventsResponse.chunk) {
              if (!Event.EVENT_TYPE_PRESENCE.equals(event.type) && !Event.EVENT_TYPE_TYPING.equals(event.type)) {
                events.add(event);
              }
            }
            eventsResponse.chunk=events;
          }
          if (mIsCatchingUp) {
            Log.e(LOG_TAG,"String_Node_Str");
            mIsCatchingUp=false;
            mPaused=true;
          }
          mListener.onEventsReceived(eventsResponse.chunk,eventsResponse.end);
          Log.d(LOG_TAG,"String_Node_Str" + eventsResponse.end);
          mCurrentToken=eventsResponse.end;
        }
        mEventRequestTimeout=EventsRestClient.EVENT_STREAM_TIMEOUT_MS;
      }
 catch (      Exception e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage() + "String_Node_Str"+ e.getStackTrace());
        if ((mEventsFailureCallback != null) && (e instanceof RetrofitError)) {
          mEventsFailureCallback.failure((RetrofitError)e);
        }
        boolean isConnected;
synchronized (this) {
          isConnected=mbIsConnected;
        }
        if (!isConnected) {
          mIsNetworkSuspended=true;
        }
      }
    }
  }
  if (null != mNetworkConnectivityReceiver) {
    mNetworkConnectivityReceiver.removeEventListener(mNetworkListener);
  }
  Log.d(LOG_TAG,"String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Use the API sync V1 to get the events
 */
private void runV1(){
  if (null != mCurrentToken) {
    Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  }
 else {
    Log.d(LOG_TAG,"String_Node_Str");
  }
  mPaused=false;
  if (null != mCurrentToken) {
    mInitialSyncDone=true;
    mListener.onInitialSyncComplete(null);
synchronized (mEventsRestClientV1) {
      mIsGettingPresences=true;
    }
    Log.d(LOG_TAG,"String_Node_Str");
    mEventsRestClientV1.initialSyncWithLimit(new SimpleApiCallback<InitialSyncResponse>(mFailureCallback){
      @Override public void onSuccess(      InitialSyncResponse initialSync){
        Log.d(LOG_TAG,"String_Node_Str");
        mListener.onMembersPresencesSyncComplete(initialSync.presence);
        Log.d(LOG_TAG,"String_Node_Str");
synchronized (mEventsRestClientV1) {
          mIsGettingPresences=false;
        }
      }
      @Override public void onNetworkError(      Exception e){
synchronized (mEventsRestClientV1) {
          mIsGettingPresences=false;
        }
      }
      @Override public void onMatrixError(      MatrixError e){
synchronized (mEventsRestClientV1) {
          mIsGettingPresences=false;
        }
      }
      @Override public void onUnexpectedError(      Exception e){
synchronized (mEventsRestClientV1) {
          mIsGettingPresences=false;
        }
      }
    }
,0);
  }
  while (!mInitialSyncDone) {
    final CountDownLatch latch=new CountDownLatch(1);
    mEventsRestClientV1.initialSyncWithLimit(new SimpleApiCallback<InitialSyncResponse>(mFailureCallback){
      @Override public void onSuccess(      InitialSyncResponse initialSync){
        Log.i(LOG_TAG,"String_Node_Str");
        mListener.onInitialSyncComplete(initialSync);
        mCurrentToken=initialSync.end;
        mInitialSyncDone=true;
        latch.countDown();
      }
      private void sleepAndUnblock(){
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable(){
          public void run(){
            latch.countDown();
          }
        }
,RETRY_WAIT_TIME_MS);
      }
      @Override public void onNetworkError(      Exception e){
        if (null != mCurrentToken) {
          onSuccess(null);
        }
 else {
          Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
          super.onNetworkError(e);
          sleepAndUnblock();
        }
      }
      @Override public void onMatrixError(      MatrixError e){
        Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
        super.onMatrixError(e);
        sleepAndUnblock();
      }
      @Override public void onUnexpectedError(      Exception e){
        super.onUnexpectedError(e);
        Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
        sleepAndUnblock();
      }
    }
,10);
    try {
      latch.await();
    }
 catch (    InterruptedException e) {
      Log.e(LOG_TAG,"String_Node_Str");
    }
  }
  Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  if (null != mNetworkConnectivityReceiver) {
    mNetworkConnectivityReceiver.addEventListener(mNetworkListener);
    mbIsConnected=mNetworkConnectivityReceiver.isConnected();
    mPaused=!mbIsConnected;
  }
  while (!mKilling) {
    if (mPaused || mIsNetworkSuspended) {
      if (mIsNetworkSuspended) {
        Log.d(LOG_TAG,"String_Node_Str");
      }
 else {
        Log.d(LOG_TAG,"String_Node_Str");
      }
      try {
synchronized (this) {
          wait();
        }
        Log.d(LOG_TAG,"String_Node_Str");
      }
 catch (      InterruptedException e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
      }
    }
    if (!mKilling) {
      try {
        Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
        TokensChunkResponse<Event> eventsResponse=mEventsRestClientV1.events(mCurrentToken,mEventRequestTimeout);
        if (null != eventsResponse.chunk) {
          Log.d(LOG_TAG,"String_Node_Str" + eventsResponse.chunk.size() + "String_Node_Str");
        }
 else {
          Log.d(LOG_TAG,"String_Node_Str");
        }
        if (!mKilling) {
          if ((null != eventsResponse.chunk) && (eventsResponse.chunk.size() > 0)) {
            eventsResponse.chunk.get(0).setIntenalPaginationToken(eventsResponse.start);
            eventsResponse.chunk.get(eventsResponse.chunk.size() - 1).setIntenalPaginationToken(eventsResponse.end);
          }
          Boolean isGettingsPresence;
synchronized (mEventsRestClientV1) {
            isGettingsPresence=mIsGettingPresences;
          }
          if (isGettingsPresence) {
            ArrayList<Event> events=new ArrayList<Event>();
            for (            Event event : eventsResponse.chunk) {
              if (!Event.EVENT_TYPE_PRESENCE.equals(event.type) && !Event.EVENT_TYPE_TYPING.equals(event.type)) {
                events.add(event);
              }
            }
            eventsResponse.chunk=events;
          }
          if (mIsCatchingUp) {
            Log.e(LOG_TAG,"String_Node_Str");
            mIsCatchingUp=false;
            mPaused=true;
          }
          mListener.onEventsReceived(eventsResponse.chunk,eventsResponse.end);
          Log.d(LOG_TAG,"String_Node_Str" + eventsResponse.end);
          mCurrentToken=eventsResponse.end;
        }
        mEventRequestTimeout=EventsRestClient.EVENT_STREAM_TIMEOUT_MS;
      }
 catch (      Exception e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage() + "String_Node_Str"+ e.getStackTrace());
        if ((mEventsFailureCallback != null) && (e instanceof RetrofitError)) {
          mEventsFailureCallback.failure((RetrofitError)e);
        }
        boolean isConnected;
synchronized (this) {
          isConnected=mbIsConnected;
        }
        if (isConnected) {
          final CountDownLatch latch=new CountDownLatch(1);
          new Handler(Looper.getMainLooper()).postDelayed(new Runnable(){
            public void run(){
              latch.countDown();
            }
          }
,RETRY_WAIT_TIME_MS);
          try {
            latch.await();
          }
 catch (          Exception anException) {
          }
        }
 else {
          mIsNetworkSuspended=true;
        }
      }
    }
  }
  if (null != mNetworkConnectivityReceiver) {
    mNetworkConnectivityReceiver.removeEventListener(mNetworkListener);
  }
  Log.d(LOG_TAG,"String_Node_Str");
}