Program: 32099
Project: 32099
Buggy source:
/** 
 * Start the events sync
 */
private void startSync(){
  if (null != mCurrentToken) {
    Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  }
 else {
    Log.d(LOG_TAG,"String_Node_Str");
  }
  int serverTimeout;
  mPaused=false;
  mInitialSyncDone=null != mCurrentToken;
  if (mInitialSyncDone) {
    serverTimeout=0;
    mListener.onSyncResponse(null,true);
  }
 else {
    while (!mInitialSyncDone) {
      final CountDownLatch latch=new CountDownLatch(1);
      mEventsRestClient.syncFromToken(null,0,DEFAULT_CLIENT_TIMEOUT_MS,null,null,new SimpleApiCallback<SyncResponse>(mFailureCallback){
        @Override public void onSuccess(        SyncResponse syncResponse){
          Log.d(LOG_TAG,"String_Node_Str");
          mListener.onSyncResponse(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);
          if (TextUtils.equals(MatrixError.UNKNOWN_TOKEN,e.errcode)) {
            mListener.onInvalidToken();
          }
 else {
            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=mServerTimeoutms;
  }
  Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  if (null != mNetworkConnectivityReceiver) {
    mNetworkConnectivityReceiver.addEventListener(mNetworkListener);
    mbIsConnected=mNetworkConnectivityReceiver.isConnected();
    mPaused=!mbIsConnected;
  }
  while (!mKilling) {
    if ((!mPaused && !mIsNetworkSuspended) && (0 != mRequestDelayMs)) {
      mSyncDelayTimer=new Timer();
      Log.d(LOG_TAG,"String_Node_Str");
      mSyncDelayTimer.schedule(new TimerTask(){
        @Override public void run(){
          Log.d(LOG_TAG,"String_Node_Str" + mRequestDelayMs + "String_Node_Str");
synchronized (mSyncObject) {
            mSyncObject.notify();
          }
        }
      }
,mRequestDelayMs);
    }
    if (mPaused || mIsNetworkSuspended || (null != mSyncDelayTimer)) {
      if (null != mSyncDelayTimer) {
        Log.d(LOG_TAG,"String_Node_Str");
      }
 else       if (mIsNetworkSuspended) {
        Log.d(LOG_TAG,"String_Node_Str");
      }
 else {
        Log.d(LOG_TAG,"String_Node_Str");
      }
      try {
        Log.d(LOG_TAG,"String_Node_Str");
synchronized (mSyncObject) {
          mSyncObject.wait();
        }
        if (null != mSyncDelayTimer) {
          mSyncDelayTimer.cancel();
          mSyncDelayTimer=null;
        }
        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=null;
      final CountDownLatch latch=new CountDownLatch(1);
      Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
      mEventsRestClient.syncFromToken(mCurrentToken,serverTimeout,DEFAULT_CLIENT_TIMEOUT_MS,(mIsCatchingUp && mIsOnline) ? "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.onSyncResponse(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 (mSyncObject) {
            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){
          if (TextUtils.equals(MatrixError.UNKNOWN_TOKEN,e.errcode)) {
            mListener.onInvalidToken();
          }
 else {
            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=mServerTimeoutms;
  }
  if (null != mNetworkConnectivityReceiver) {
    mNetworkConnectivityReceiver.removeEventListener(mNetworkListener);
  }
  Log.d(LOG_TAG,"String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Start the events sync
 */
private void startSync(){
  if (null != mCurrentToken) {
    Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  }
 else {
    Log.d(LOG_TAG,"String_Node_Str");
  }
  int serverTimeout;
  mPaused=false;
  mInitialSyncDone=null != mCurrentToken;
  if (mInitialSyncDone) {
    serverTimeout=0;
    mListener.onSyncResponse(null,true);
  }
 else {
    while (!mInitialSyncDone) {
      final CountDownLatch latch=new CountDownLatch(1);
      mEventsRestClient.syncFromToken(null,0,DEFAULT_CLIENT_TIMEOUT_MS,null,null,new SimpleApiCallback<SyncResponse>(mFailureCallback){
        @Override public void onSuccess(        SyncResponse syncResponse){
          Log.d(LOG_TAG,"String_Node_Str");
          mListener.onSyncResponse(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);
          if (TextUtils.equals(MatrixError.UNKNOWN_TOKEN,e.errcode)) {
            mListener.onInvalidToken();
          }
 else {
            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=mServerTimeoutms;
  }
  Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
  if (null != mNetworkConnectivityReceiver) {
    mNetworkConnectivityReceiver.addEventListener(mNetworkListener);
    mbIsConnected=mNetworkConnectivityReceiver.isConnected();
    mIsNetworkSuspended=!mbIsConnected;
  }
  while (!mKilling) {
    if ((!mPaused && !mIsNetworkSuspended) && (0 != mRequestDelayMs)) {
      mSyncDelayTimer=new Timer();
      Log.d(LOG_TAG,"String_Node_Str");
      mSyncDelayTimer.schedule(new TimerTask(){
        @Override public void run(){
          Log.d(LOG_TAG,"String_Node_Str" + mRequestDelayMs + "String_Node_Str");
synchronized (mSyncObject) {
            mSyncObject.notify();
          }
        }
      }
,mRequestDelayMs);
    }
    if (mPaused || mIsNetworkSuspended || (null != mSyncDelayTimer)) {
      if (null != mSyncDelayTimer) {
        Log.d(LOG_TAG,"String_Node_Str");
      }
 else       if (mIsNetworkSuspended) {
        Log.d(LOG_TAG,"String_Node_Str");
      }
 else {
        Log.d(LOG_TAG,"String_Node_Str");
      }
      try {
        Log.d(LOG_TAG,"String_Node_Str");
synchronized (mSyncObject) {
          mSyncObject.wait();
        }
        if (null != mSyncDelayTimer) {
          mSyncDelayTimer.cancel();
          mSyncDelayTimer=null;
        }
        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=null;
      final CountDownLatch latch=new CountDownLatch(1);
      Log.d(LOG_TAG,"String_Node_Str" + mCurrentToken);
      mEventsRestClient.syncFromToken(mCurrentToken,serverTimeout,DEFAULT_CLIENT_TIMEOUT_MS,(mIsCatchingUp && mIsOnline) ? "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.onSyncResponse(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 (mSyncObject) {
            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){
          if (TextUtils.equals(MatrixError.UNKNOWN_TOKEN,e.errcode)) {
            mListener.onInvalidToken();
          }
 else {
            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=mServerTimeoutms;
  }
  if (null != mNetworkConnectivityReceiver) {
    mNetworkConnectivityReceiver.removeEventListener(mNetworkListener);
  }
  Log.d(LOG_TAG,"String_Node_Str");
}