Program: 193399
Project: 193399
Buggy source:
private long maybeStartNextSyncH(){
  final boolean isLoggable=Log.isLoggable(TAG,Log.VERBOSE);
  if (isLoggable)   Log.v(TAG,"String_Node_Str");
  if (!mDataConnectionIsConnected) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str");
    }
    return Long.MAX_VALUE;
  }
  if (mStorageIsLow) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str");
    }
    return Long.MAX_VALUE;
  }
  if (mDeviceIsIdle) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str");
    }
    return Long.MAX_VALUE;
  }
  if (mRunningAccounts == INITIAL_ACCOUNTS_ARRAY) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str");
    }
    return Long.MAX_VALUE;
  }
  final long now=SystemClock.elapsedRealtime();
  long nextReadyToRunTime=Long.MAX_VALUE;
  ArrayList<SyncOperation> operations=new ArrayList<SyncOperation>();
synchronized (mSyncQueue) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str" + mSyncQueue.getOperations().size());
    }
    final Iterator<SyncOperation> operationIterator=mSyncQueue.getOperations().iterator();
    final ActivityManager activityManager=(ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
    final Set<Integer> removedUsers=Sets.newHashSet();
    while (operationIterator.hasNext()) {
      final SyncOperation op=operationIterator.next();
      if (!activityManager.isUserRunning(op.target.userId)) {
        final UserInfo userInfo=mUserManager.getUserInfo(op.target.userId);
        if (userInfo == null) {
          removedUsers.add(op.target.userId);
        }
        if (isLoggable) {
          Log.v(TAG,"String_Node_Str" + op.target.userId + "String_Node_Str");
        }
        continue;
      }
      if (!isOperationValidLocked(op)) {
        operationIterator.remove();
        mSyncStorageEngine.deleteFromPending(op.pendingOperation);
        continue;
      }
      if (op.effectiveRunTime - op.flexTime > now) {
        if (nextReadyToRunTime > op.effectiveRunTime) {
          nextReadyToRunTime=op.effectiveRunTime;
        }
        if (isLoggable) {
          Log.v(TAG,"String_Node_Str" + "String_Node_Str" + op.effectiveRunTime + "String_Node_Str"+ op.flexTime+ "String_Node_Str"+ now);
        }
        continue;
      }
      String packageName=getPackageName(op.target);
      if (packageName != null && mAppIdleMonitor.isAppIdle(packageName,op.target.userId)) {
        increaseBackoffSetting(op);
        op.appIdle=true;
        if (isLoggable) {
          Log.v(TAG,"String_Node_Str" + packageName);
        }
        continue;
      }
 else {
        op.appIdle=false;
      }
      operations.add(op);
    }
    for (    Integer user : removedUsers) {
      if (mUserManager.getUserInfo(user) == null) {
        onUserRemoved(user);
      }
    }
  }
  if (isLoggable)   Log.v(TAG,"String_Node_Str" + operations.size());
  Collections.sort(operations);
  if (isLoggable)   Log.v(TAG,"String_Node_Str");
  for (int i=0, N=operations.size(); i < N; i++) {
    final SyncOperation candidate=operations.get(i);
    final boolean candidateIsInitialization=candidate.isInitialization();
    int numInit=0;
    int numRegular=0;
    ActiveSyncContext conflict=null;
    ActiveSyncContext longRunning=null;
    ActiveSyncContext toReschedule=null;
    ActiveSyncContext oldestNonExpeditedRegular=null;
    for (    ActiveSyncContext activeSyncContext : mActiveSyncContexts) {
      final SyncOperation activeOp=activeSyncContext.mSyncOperation;
      if (activeOp.isInitialization()) {
        numInit++;
      }
 else {
        numRegular++;
        if (!activeOp.isExpedited()) {
          if (oldestNonExpeditedRegular == null || (oldestNonExpeditedRegular.mStartTime > activeSyncContext.mStartTime)) {
            oldestNonExpeditedRegular=activeSyncContext;
          }
        }
      }
      if (activeOp.isConflict(candidate)) {
        conflict=activeSyncContext;
      }
 else {
        if (candidateIsInitialization == activeOp.isInitialization() && activeSyncContext.mStartTime + MAX_TIME_PER_SYNC < now) {
          longRunning=activeSyncContext;
        }
      }
    }
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str" + (i + 1) + "String_Node_Str"+ N+ "String_Node_Str"+ candidate);
      Log.v(TAG,"String_Node_Str" + numInit + "String_Node_Str"+ numRegular);
      Log.v(TAG,"String_Node_Str" + longRunning);
      Log.v(TAG,"String_Node_Str" + conflict);
      Log.v(TAG,"String_Node_Str" + oldestNonExpeditedRegular);
    }
    final boolean roomAvailable=candidateIsInitialization ? numInit < MAX_SIMULTANEOUS_INITIALIZATION_SYNCS : numRegular < MAX_SIMULTANEOUS_REGULAR_SYNCS;
    if (conflict != null) {
      if (candidateIsInitialization && !conflict.mSyncOperation.isInitialization() && numInit < MAX_SIMULTANEOUS_INITIALIZATION_SYNCS) {
        toReschedule=conflict;
        if (Log.isLoggable(TAG,Log.VERBOSE)) {
          Log.v(TAG,"String_Node_Str" + "String_Node_Str" + conflict);
        }
      }
 else       if (candidate.isExpedited() && !conflict.mSyncOperation.isExpedited() && (candidateIsInitialization == conflict.mSyncOperation.isInitialization())) {
        toReschedule=conflict;
        if (Log.isLoggable(TAG,Log.VERBOSE)) {
          Log.v(TAG,"String_Node_Str" + "String_Node_Str" + conflict);
        }
      }
 else {
        continue;
      }
    }
 else     if (roomAvailable) {
    }
 else     if (candidate.isExpedited() && oldestNonExpeditedRegular != null && !candidateIsInitialization) {
      toReschedule=oldestNonExpeditedRegular;
      if (Log.isLoggable(TAG,Log.VERBOSE)) {
        Log.v(TAG,"String_Node_Str" + "String_Node_Str" + oldestNonExpeditedRegular);
      }
    }
 else     if (longRunning != null && (candidateIsInitialization == longRunning.mSyncOperation.isInitialization())) {
      toReschedule=longRunning;
      if (Log.isLoggable(TAG,Log.VERBOSE)) {
        Log.v(TAG,"String_Node_Str" + longRunning);
      }
    }
 else {
      continue;
    }
    if (toReschedule != null) {
      runSyncFinishedOrCanceledH(null,toReschedule);
      scheduleSyncOperation(toReschedule.mSyncOperation);
    }
synchronized (mSyncQueue) {
      mSyncQueue.remove(candidate);
    }
    dispatchSyncOperation(candidate);
  }
  return nextReadyToRunTime;
}

Fixed version (ground truth):
private long maybeStartNextSyncH(){
  final boolean isLoggable=Log.isLoggable(TAG,Log.VERBOSE);
  if (isLoggable)   Log.v(TAG,"String_Node_Str");
  if (!mDataConnectionIsConnected) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str");
    }
    return Long.MAX_VALUE;
  }
  if (mStorageIsLow) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str");
    }
    return Long.MAX_VALUE;
  }
  if (mDeviceIsIdle) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str");
    }
    return Long.MAX_VALUE;
  }
  if (mRunningAccounts == INITIAL_ACCOUNTS_ARRAY) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str");
    }
    return Long.MAX_VALUE;
  }
  final long now=SystemClock.elapsedRealtime();
  long nextReadyToRunTime=Long.MAX_VALUE;
  ArrayList<SyncOperation> operations=new ArrayList<SyncOperation>();
synchronized (mSyncQueue) {
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str" + mSyncQueue.getOperations().size());
    }
    final Iterator<SyncOperation> operationIterator=mSyncQueue.getOperations().iterator();
    final ActivityManager activityManager=(ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
    final Set<Integer> removedUsers=Sets.newHashSet();
    while (operationIterator.hasNext()) {
      final SyncOperation op=operationIterator.next();
      if (!activityManager.isUserRunning(op.target.userId)) {
        final UserInfo userInfo=mUserManager.getUserInfo(op.target.userId);
        if (userInfo == null) {
          removedUsers.add(op.target.userId);
        }
        if (isLoggable) {
          Log.v(TAG,"String_Node_Str" + op.target.userId + "String_Node_Str");
        }
        continue;
      }
      if (!isOperationValidLocked(op)) {
        operationIterator.remove();
        mSyncStorageEngine.deleteFromPending(op.pendingOperation);
        continue;
      }
      if (op.effectiveRunTime - op.flexTime > now) {
        if (nextReadyToRunTime > op.effectiveRunTime) {
          nextReadyToRunTime=op.effectiveRunTime;
        }
        if (isLoggable) {
          Log.v(TAG,"String_Node_Str" + "String_Node_Str" + op.effectiveRunTime + "String_Node_Str"+ op.flexTime+ "String_Node_Str"+ now);
        }
        continue;
      }
      String packageName=getPackageName(op.target);
      ApplicationInfo ai=null;
      if (packageName != null) {
        try {
          ai=mContext.getPackageManager().getApplicationInfo(packageName,PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_DISABLED_COMPONENTS);
        }
 catch (        NameNotFoundException e) {
        }
      }
      if (ai != null && mAppIdleMonitor.isAppIdle(packageName,ai.uid,op.target.userId)) {
        increaseBackoffSetting(op);
        op.appIdle=true;
        if (isLoggable) {
          Log.v(TAG,"String_Node_Str" + packageName);
        }
        continue;
      }
 else {
        op.appIdle=false;
      }
      operations.add(op);
    }
    for (    Integer user : removedUsers) {
      if (mUserManager.getUserInfo(user) == null) {
        onUserRemoved(user);
      }
    }
  }
  if (isLoggable)   Log.v(TAG,"String_Node_Str" + operations.size());
  Collections.sort(operations);
  if (isLoggable)   Log.v(TAG,"String_Node_Str");
  for (int i=0, N=operations.size(); i < N; i++) {
    final SyncOperation candidate=operations.get(i);
    final boolean candidateIsInitialization=candidate.isInitialization();
    int numInit=0;
    int numRegular=0;
    ActiveSyncContext conflict=null;
    ActiveSyncContext longRunning=null;
    ActiveSyncContext toReschedule=null;
    ActiveSyncContext oldestNonExpeditedRegular=null;
    for (    ActiveSyncContext activeSyncContext : mActiveSyncContexts) {
      final SyncOperation activeOp=activeSyncContext.mSyncOperation;
      if (activeOp.isInitialization()) {
        numInit++;
      }
 else {
        numRegular++;
        if (!activeOp.isExpedited()) {
          if (oldestNonExpeditedRegular == null || (oldestNonExpeditedRegular.mStartTime > activeSyncContext.mStartTime)) {
            oldestNonExpeditedRegular=activeSyncContext;
          }
        }
      }
      if (activeOp.isConflict(candidate)) {
        conflict=activeSyncContext;
      }
 else {
        if (candidateIsInitialization == activeOp.isInitialization() && activeSyncContext.mStartTime + MAX_TIME_PER_SYNC < now) {
          longRunning=activeSyncContext;
        }
      }
    }
    if (isLoggable) {
      Log.v(TAG,"String_Node_Str" + (i + 1) + "String_Node_Str"+ N+ "String_Node_Str"+ candidate);
      Log.v(TAG,"String_Node_Str" + numInit + "String_Node_Str"+ numRegular);
      Log.v(TAG,"String_Node_Str" + longRunning);
      Log.v(TAG,"String_Node_Str" + conflict);
      Log.v(TAG,"String_Node_Str" + oldestNonExpeditedRegular);
    }
    final boolean roomAvailable=candidateIsInitialization ? numInit < MAX_SIMULTANEOUS_INITIALIZATION_SYNCS : numRegular < MAX_SIMULTANEOUS_REGULAR_SYNCS;
    if (conflict != null) {
      if (candidateIsInitialization && !conflict.mSyncOperation.isInitialization() && numInit < MAX_SIMULTANEOUS_INITIALIZATION_SYNCS) {
        toReschedule=conflict;
        if (Log.isLoggable(TAG,Log.VERBOSE)) {
          Log.v(TAG,"String_Node_Str" + "String_Node_Str" + conflict);
        }
      }
 else       if (candidate.isExpedited() && !conflict.mSyncOperation.isExpedited() && (candidateIsInitialization == conflict.mSyncOperation.isInitialization())) {
        toReschedule=conflict;
        if (Log.isLoggable(TAG,Log.VERBOSE)) {
          Log.v(TAG,"String_Node_Str" + "String_Node_Str" + conflict);
        }
      }
 else {
        continue;
      }
    }
 else     if (roomAvailable) {
    }
 else     if (candidate.isExpedited() && oldestNonExpeditedRegular != null && !candidateIsInitialization) {
      toReschedule=oldestNonExpeditedRegular;
      if (Log.isLoggable(TAG,Log.VERBOSE)) {
        Log.v(TAG,"String_Node_Str" + "String_Node_Str" + oldestNonExpeditedRegular);
      }
    }
 else     if (longRunning != null && (candidateIsInitialization == longRunning.mSyncOperation.isInitialization())) {
      toReschedule=longRunning;
      if (Log.isLoggable(TAG,Log.VERBOSE)) {
        Log.v(TAG,"String_Node_Str" + longRunning);
      }
    }
 else {
      continue;
    }
    if (toReschedule != null) {
      runSyncFinishedOrCanceledH(null,toReschedule);
      scheduleSyncOperation(toReschedule.mSyncOperation);
    }
synchronized (mSyncQueue) {
      mSyncQueue.remove(candidate);
    }
    dispatchSyncOperation(candidate);
  }
  return nextReadyToRunTime;
}