Program: 32185
Project: 32185
Buggy source:
/** 
 * Use the API sync V1 to get the events
 */
private void runV2(){
  if (null != mCurrentToken) {
    Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  }
 else {
    Log.d(LOG_TAG,"String_Node_Str");
  }
  int serverTimeout=0;
  mPaused=false;
  mInitialSyncDone=null != mCurrentToken;
  if (mInitialSyncDone) {
    serverTimeout=0;
    mListener.onSyncV2Reponse(null,true);
  }
 else {
    while (!mInitialSyncDone) {
      final CountDownLatch latch=new CountDownLatch(1);
      mEventsRestClientV2.syncFromToken(null,0,CLIENT_TIMEOUT_MS,null,null,new SimpleApiCallback<SyncResponse>(mFailureCallback){
        @Override public void onSuccess(        SyncResponse syncResponse){
          Log.d(LOG_TAG,"String_Node_Str");
          mListener.onSyncV2Reponse(syncResponse,true);
          mCurrentToken=syncResponse.nextBatch;
          mInitialSyncDone=true;
          latch.countDown();
        }
        private void sleepAndUnblock(){
          Log.i(LOG_TAG,"String_Node_Str");
          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){
          super.onMatrixError(e);
          Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
          sleepAndUnblock();
        }
        @Override public void onUnexpectedError(        Exception e){
          super.onUnexpectedError(e);
          Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
          sleepAndUnblock();
        }
      }
);
      try {
        latch.await();
      }
 catch (      InterruptedException e) {
        Log.e(LOG_TAG,"String_Node_Str");
      }
    }
    serverTimeout=SERVER_TIMEOUT_MS;
  }
  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");
        serverTimeout=0;
      }
 catch (      InterruptedException e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
      }
    }
    if (!mKilling) {
      String inlineFilter="String_Node_Str";
      final CountDownLatch latch=new CountDownLatch(1);
      Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
      mEventsRestClientV2.syncFromToken(mCurrentToken,serverTimeout,CLIENT_TIMEOUT_MS,mIsCatchingUp ? "String_Node_Str" : null,inlineFilter,new SimpleApiCallback<SyncResponse>(mFailureCallback){
        @Override public void onSuccess(        SyncResponse syncResponse){
          if (!mKilling) {
            if (mIsCatchingUp) {
              Log.e(LOG_TAG,"String_Node_Str");
              mIsCatchingUp=false;
              mPaused=true;
            }
            Log.d(LOG_TAG,"String_Node_Str");
            mListener.onSyncV2Reponse(syncResponse,false);
            mCurrentToken=syncResponse.nextBatch;
            Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
          }
          latch.countDown();
        }
        private void onError(        String description){
          boolean isConnected;
          Log.d(LOG_TAG,"String_Node_Str" + description);
synchronized (this) {
            isConnected=mbIsConnected;
          }
          if (!isConnected) {
            mIsNetworkSuspended=true;
          }
          latch.countDown();
        }
        @Override public void onNetworkError(        Exception e){
          onError(e.getLocalizedMessage());
        }
        @Override public void onMatrixError(        MatrixError e){
          onError(e.getLocalizedMessage());
        }
        @Override public void onUnexpectedError(        Exception e){
          onError(e.getLocalizedMessage());
        }
      }
);
      try {
        latch.await();
      }
 catch (      InterruptedException e) {
        Log.e(LOG_TAG,"String_Node_Str");
      }
    }
    serverTimeout=SERVER_TIMEOUT_MS;
  }
  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 runV2(){
  if (null != mCurrentToken) {
    Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  }
 else {
    Log.d(LOG_TAG,"String_Node_Str");
  }
  int serverTimeout=0;
  mPaused=false;
  mInitialSyncDone=null != mCurrentToken;
  if (mInitialSyncDone) {
    serverTimeout=0;
    mListener.onSyncV2Reponse(null,true);
  }
 else {
    while (!mInitialSyncDone) {
      final CountDownLatch latch=new CountDownLatch(1);
      mEventsRestClientV2.syncFromToken(null,0,CLIENT_TIMEOUT_MS,null,null,new SimpleApiCallback<SyncResponse>(mFailureCallback){
        @Override public void onSuccess(        SyncResponse syncResponse){
          Log.d(LOG_TAG,"String_Node_Str");
          mListener.onSyncV2Reponse(syncResponse,true);
          mCurrentToken=syncResponse.nextBatch;
          mInitialSyncDone=true;
          latch.countDown();
        }
        private void sleepAndUnblock(){
          Log.i(LOG_TAG,"String_Node_Str");
          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){
          super.onMatrixError(e);
          Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
          sleepAndUnblock();
        }
        @Override public void onUnexpectedError(        Exception e){
          super.onUnexpectedError(e);
          Log.e(LOG_TAG,"String_Node_Str" + e.getLocalizedMessage());
          sleepAndUnblock();
        }
      }
);
      try {
        latch.await();
      }
 catch (      InterruptedException e) {
        Log.e(LOG_TAG,"String_Node_Str");
      }
    }
    serverTimeout=SERVER_TIMEOUT_MS;
  }
  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");
        serverTimeout=0;
      }
 catch (      InterruptedException e) {
        Log.e(LOG_TAG,"String_Node_Str" + e.getMessage());
      }
    }
    if (!mKilling) {
      String inlineFilter="String_Node_Str";
      final CountDownLatch latch=new CountDownLatch(1);
      Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
      mEventsRestClientV2.syncFromToken(mCurrentToken,serverTimeout,CLIENT_TIMEOUT_MS,mIsCatchingUp ? "String_Node_Str" : null,inlineFilter,new SimpleApiCallback<SyncResponse>(mFailureCallback){
        @Override public void onSuccess(        SyncResponse syncResponse){
          if (!mKilling) {
            if (mIsCatchingUp) {
              Log.e(LOG_TAG,"String_Node_Str");
              mIsCatchingUp=false;
              mPaused=true;
            }
            Log.d(LOG_TAG,"String_Node_Str");
            mListener.onSyncV2Reponse(syncResponse,false);
            mCurrentToken=syncResponse.nextBatch;
            Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
          }
          latch.countDown();
        }
        private void onError(        String description){
          boolean isConnected;
          Log.d(LOG_TAG,"String_Node_Str" + description);
synchronized (this) {
            isConnected=mbIsConnected;
          }
          if (isConnected) {
            new Handler(Looper.getMainLooper()).postDelayed(new Runnable(){
              public void run(){
                latch.countDown();
              }
            }
,RETRY_WAIT_TIME_MS);
          }
 else {
            mIsNetworkSuspended=true;
            latch.countDown();
          }
        }
        @Override public void onNetworkError(        Exception e){
          onError(e.getLocalizedMessage());
        }
        @Override public void onMatrixError(        MatrixError e){
          onError(e.getLocalizedMessage());
        }
        @Override public void onUnexpectedError(        Exception e){
          onError(e.getLocalizedMessage());
        }
      }
);
      try {
        latch.await();
      }
 catch (      InterruptedException e) {
        Log.e(LOG_TAG,"String_Node_Str");
      }
    }
    serverTimeout=SERVER_TIMEOUT_MS;
  }
  if (null != mNetworkConnectivityReceiver) {
    mNetworkConnectivityReceiver.removeEventListener(mNetworkListener);
  }
  Log.d(LOG_TAG,"String_Node_Str");
}