Program: 2914
Project: 2914
Buggy source:
boolean removeHistoryRecordsForAppLocked(ProcessRecord app){
  removeHistoryRecordsForAppLocked(mLRUActivities,app,"String_Node_Str");
  removeHistoryRecordsForAppLocked(mStoppingActivities,app,"String_Node_Str");
  removeHistoryRecordsForAppLocked(mGoingToSleepActivities,app,"String_Node_Str");
  removeHistoryRecordsForAppLocked(mWaitingVisibleActivities,app,"String_Node_Str");
  removeHistoryRecordsForAppLocked(mFinishingActivities,app,"String_Node_Str");
  boolean hasVisibleActivities=false;
  int i=mHistory.size();
  if (DEBUG_CLEANUP)   Slog.v(TAG,"String_Node_Str" + app + "String_Node_Str"+ i+ "String_Node_Str");
  while (i > 0) {
    i--;
    ActivityRecord r=(ActivityRecord)mHistory.get(i);
    if (DEBUG_CLEANUP)     Slog.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ r+ "String_Node_Str"+ r.app);
    if (r.app == app) {
      if ((!r.haveState && !r.stateNotNeeded) || r.finishing) {
        if (ActivityStack.DEBUG_ADD_REMOVE || DEBUG_CLEANUP) {
          RuntimeException here=new RuntimeException("String_Node_Str");
          here.fillInStackTrace();
          Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ i+ "String_Node_Str"+ r.haveState+ "String_Node_Str"+ r.stateNotNeeded+ "String_Node_Str"+ r.finishing+ "String_Node_Str"+ r.state,here);
        }
        if (!r.finishing) {
          Slog.w(TAG,"String_Node_Str" + r + "String_Node_Str");
          EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY,r.userId,System.identityHashCode(r),r.task.taskId,r.shortComponentName,"String_Node_Str");
        }
        removeActivityFromHistoryLocked(r);
      }
 else {
        if (localLOGV)         Slog.v(TAG,"String_Node_Str");
        if (r.visible) {
          hasVisibleActivities=true;
        }
        r.app=null;
        r.nowVisible=false;
        if (!r.haveState) {
          if (ActivityStack.DEBUG_SAVED_STATE)           Slog.i(TAG,"String_Node_Str" + r);
          r.icicle=null;
        }
      }
      r.stack.cleanUpActivityLocked(r,true,true);
    }
  }
  return hasVisibleActivities;
}

Fixed version (ground truth):
boolean removeHistoryRecordsForAppLocked(ProcessRecord app){
  removeHistoryRecordsForAppLocked(mLRUActivities,app,"String_Node_Str");
  removeHistoryRecordsForAppLocked(mStoppingActivities,app,"String_Node_Str");
  removeHistoryRecordsForAppLocked(mGoingToSleepActivities,app,"String_Node_Str");
  removeHistoryRecordsForAppLocked(mWaitingVisibleActivities,app,"String_Node_Str");
  removeHistoryRecordsForAppLocked(mFinishingActivities,app,"String_Node_Str");
  boolean hasVisibleActivities=false;
  int i=mHistory.size();
  if (DEBUG_CLEANUP)   Slog.v(TAG,"String_Node_Str" + app + "String_Node_Str"+ i+ "String_Node_Str");
  while (i > 0) {
    i--;
    ActivityRecord r=(ActivityRecord)mHistory.get(i);
    if (DEBUG_CLEANUP)     Slog.v(TAG,"String_Node_Str" + i + "String_Node_Str"+ r+ "String_Node_Str"+ r.app);
    if (r.app == app) {
      boolean remove;
      if ((!r.haveState && !r.stateNotNeeded) || r.finishing) {
        remove=true;
      }
 else       if (r.launchCount > 2 && r.lastLaunchTime > (SystemClock.uptimeMillis() - 60000)) {
        remove=true;
      }
 else {
        remove=false;
      }
      if (remove) {
        if (ActivityStack.DEBUG_ADD_REMOVE || DEBUG_CLEANUP) {
          RuntimeException here=new RuntimeException("String_Node_Str");
          here.fillInStackTrace();
          Slog.i(TAG,"String_Node_Str" + r + "String_Node_Str"+ i+ "String_Node_Str"+ r.haveState+ "String_Node_Str"+ r.stateNotNeeded+ "String_Node_Str"+ r.finishing+ "String_Node_Str"+ r.state,here);
        }
        if (!r.finishing) {
          Slog.w(TAG,"String_Node_Str" + r + "String_Node_Str");
          EventLog.writeEvent(EventLogTags.AM_FINISH_ACTIVITY,r.userId,System.identityHashCode(r),r.task.taskId,r.shortComponentName,"String_Node_Str");
        }
        removeActivityFromHistoryLocked(r);
      }
 else {
        if (localLOGV)         Slog.v(TAG,"String_Node_Str");
        if (r.visible) {
          hasVisibleActivities=true;
        }
        if (DEBUG_APP)         Slog.v(TAG,"String_Node_Str" + r);
        r.app=null;
        r.nowVisible=false;
        if (!r.haveState) {
          if (ActivityStack.DEBUG_SAVED_STATE)           Slog.i(TAG,"String_Node_Str" + r);
          r.icicle=null;
        }
      }
      r.stack.cleanUpActivityLocked(r,true,true);
    }
  }
  return hasVisibleActivities;
}